-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·85 lines (76 loc) · 2.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>streaming player</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<video id="videoPlayer" controls></video>
<label for="mpd_url">mpd file url</label>
<input type="text" id="mpd_url">
<button class="url_btn">load</button>
<div class="monitor_box">
<strong>Real time bitrate: </strong>
<span class="bitrate">0 Kbps</span>
<br>
<strong>Resolution: </strong>
<span class="resolution">0 x 0</span>
<br>
</div>
<script src="dash.js-master/dist/dash.all.min.js"></script>
<script>
let submit_btn = document.querySelector(".url_btn");
submit_btn.addEventListener("click", load);
let player = dashjs.MediaPlayer().create();
let timestamp = 0
let stall_count = []
let bitrate_count = []
let interval_id = []
function load(e) {
if (interval_id !== [])
clearInterval(interval_id);
//var url = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd"
timestamp = 0
if (stall_count.length !== 0) {
console.log("stall:\n")
console.log(stall_count.slice())
stall_count = []
}
if (bitrate_count.length !== 0) {
console.log("bitrate:\n")
console.log(bitrate_count.slice())
console.log(eval(bitrate_count.join("+")))
bitrate_count = []
}
player.initialize(document.querySelector("#videoPlayer"), document.querySelector("#mpd_url").value, false)
player.on(dashjs.MediaPlayer.events.PLAYBACK_PAUSED, stall_handler)
player.on(dashjs.MediaPlayer.events.PLAYBACK_PLAYING, stall_handler)
let video_ele = document.querySelector('#videoPlayer')
let last = video_ele.webkitVideoDecodedByteCount
interval_id = setInterval(() => {
let metrix = player.getDashMetrics()
video_ele = document.querySelector('#videoPlayer')
let real_bitrate = document.querySelector(".bitrate")
let resolution = document.querySelector(".resolution")
real_bitrate.innerHTML = `${Math.round((video_ele.webkitVideoDecodedByteCount - last) / 5000 * 8)} Kbps`
resolution.innerHTML = `${video_ele.videoWidth} x ${video_ele.videoHeight}`
bitrate_count.push(video_ele.webkitVideoDecodedByteCount - last)
last = video_ele.webkitVideoDecodedByteCount
}, 5000)
}
function stall_handler(e) {
//console.log(e);
if (e.type === dashjs.MediaPlayer.events.PLAYBACK_PAUSED) {
let now = new Date()
timestamp = now.getTime()
}
else if (e.type === dashjs.MediaPlayer.events.PLAYBACK_PLAYING && timestamp !== 0) {
let now = new Date()
stall_count.push(now.getTime() - timestamp)
//console.log(`diff : ${now.getTime() - timestamp}ms`)
}
}
</script>
</body>
</html>