forked from Dash-Industry-Forum/dash.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sequence2.html
154 lines (119 loc) · 4.97 KB
/
test_sequence2.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>MediaSource Test</title>
<meta name="description" content="" />
<script>
var ms,
sourceBuffer,
video,
baseUrl = "http://origintest.cloudapp.net/media/SintelTrailer_Smooth_from_WAME_720p_Main_Profile/sintel_trailer-720p.ism/",
mimetype,
codec,
loaded = 0,
initialization,
frags,
playbackStarted = false;
function loadVideo() {
mimetype = "video/mp4";
codec = "avc1.4D4020";
initialization = baseUrl + "QualityLevels(1000000)/Fragments(video=i,format=mpd-time-csf)";
frags = [];
frags.push(baseUrl + "QualityLevels(1000000)/Fragments(video=0,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(1000000)/Fragments(video=19999967,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(1000000)/Fragments(video=39999935,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(1000000)/Fragments(video=59999904,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(1000000)/Fragments(video=79999871,format=mpd-time-csf)");
load();
}
function loadAudio() {
mimetype = "audio/mp4";
codec = "mp4a.40.2";
initialization = baseUrl + "QualityLevels(96000)/Fragments(audio=i,format=mpd-time-csf)";
frags = [];
frags.push(baseUrl + "QualityLevels(96000)/Fragments(audio=0,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(96000)/Fragments(audio=20201360,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(96000)/Fragments(audio=40170521,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(96000)/Fragments(audio=60139682,format=mpd-time-csf)");
frags.push(baseUrl + "QualityLevels(96000)/Fragments(audio=80108843,format=mpd-time-csf)");
load();
}
function load() {
console.log("FRAGMENTS:");
console.log(frags);
console.log("START");
window.MediaSource = window.MediaSource || window.WebKitMediaSource;
ms = new MediaSource();
video = document.querySelector('video');
video.src = window.URL.createObjectURL(ms);
ms.addEventListener('webkitsourceopen', opened, false);
ms.addEventListener('webkitsourceclose', closed, false);
}
function opened() {
var value = mimetype + ';codecs="' + codec + '"',
url = initialization;
console.log("OPENED");
console.log(value);
sourceBuffer = ms.addSourceBuffer(value);
console.log("LOAD INIT");
var req = new XMLHttpRequest();
req.responseType = "arraybuffer";
req.open("GET", url, true);
req.onload = function () {
console.log("INIT DONE LOADING");
sourceBuffer.append(new Uint8Array(req.response));
loadNext();
}
req.onerror = function () {
alert("Could not load init.");
}
req.send();
}
function loadNext() {
if (loaded >= frags.length) {
console.log("EVERYTHING IS LOADED!");
return;
}
var url = frags[loaded],
i,
len,
ranges = sourceBuffer.buffered;
console.log("--STATUS-------");
console.log("CURRENT TIME: " + video.currentTime);
console.log("BUFFERED RANGES: " + ranges.length);
for (i = 0, len = ranges.length; i < len; i += 1) {
console.log("RANGE: " + ranges.start(i) + " - " + ranges.end(i));
}
console.log("---------------");
console.log("LOAD FRAGMENT: " + url);
var req = new XMLHttpRequest();
req.responseType = "arraybuffer";
req.open("GET", url, true);
req.onload = function () {
console.log("FRAGMENT DONE LOADING");
sourceBuffer.append(new Uint8Array(req.response));
if (!playbackStarted) {
playbackStarted = true;
video.play();
video.currentTime = sourceBuffer.buffered.start(0);
}
loaded += 1;
loadNext();
}
req.onerror = function () {
alert("Could not load fragment.");
}
req.send();
}
function closed() {
alert("MediaSource Closed.");
}
</script>
</head>
<body>
<button type="button" onclick="loadVideo()">Load Video</button>
<button type="button" onclick="loadAudio()">Load Audio</button>
<video controls autoplay width="320" height="240"></video>
</body>
</html>