forked from Dash-Industry-Forum/dash.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
191 lines (155 loc) · 6.72 KB
/
test.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>MediaSource Test</title>
<meta name="description" content="" />
<script>
var ms,
sourceBuffer,
video;
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function init() {
var mimetypeInput = document.getElementById("mimetype-source"),
codecInput = document.getElementById("codec-source"),
initInput = document.getElementById("init-source"),
initRangeInput = document.getElementById("init-range"),
fragInput = document.getElementById("frag-source"),
fragRangeInput = document.getElementById("frag-range");
var mimetype = getParameterByName("mimetype"),
codec = getParameterByName("codec"),
init = getParameterByName("initialization"),
initRange = getParameterByName("initrange"),
frag = getParameterByName("fragment"),
fragRange = getParameterByName("fragrange");
if (mimetype !== null && mimetype !== undefined && mimetype !== "")
mimetypeInput.value = mimetype;
if (codec !== null && codec !== undefined && codec !== "")
codecInput.value = codec;
if (init !== null && init !== undefined && init !== "")
initInput.value = init;
if (initRange !== null && initRange !== undefined && initRange !== "")
initRangeInput.value = initRange;
if (frag !== null && frag !== undefined && frag !== "")
fragInput.value = frag;
if (fragRange !== null && fragRange !== undefined && fragRange !== "")
fragRangeInput.value = fragRange;
}
function load() {
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 codecInput = document.getElementById("codec-source"),
codecStr = codecInput.value,
typeInput = document.getElementById("mimetype-source"),
typeStr = typeInput.value,
value = typeStr + ';codecs="' + codecStr + '"';
console.log("OPENED");
console.log(value);
sourceBuffer = ms.addSourceBuffer(value);
loadInit();
}
function loadInit() {
var input = document.getElementById("init-source"),
url = input.value,
rinput = document.getElementById("init-range"),
range = rinput.value;
if (url !== "") {
console.log("LOAD INIT");
var req = new XMLHttpRequest();
req.responseType = "arraybuffer";
req.open("GET", url, true);
if (range !== undefined && range !== null && range.length > 0)
req.setRequestHeader("Range", "bytes=" + range);
req.onload = function () {
console.log("INIT DONE LOADING");
sourceBuffer.append(new Uint8Array(req.response));
loadFragment();
}
req.onerror = function () {
alert("Could not load init.");
}
req.send();
} else {
loadFragment();
}
}
function loadFragment() {
var input = document.getElementById("frag-source"),
url = input.value,
rinput = document.getElementById("frag-range"),
range = rinput.value;
if (url !== "") {
console.log("LOAD FRAGMENT");
var req = new XMLHttpRequest();
req.responseType = "arraybuffer";
req.open("GET", url, true);
if (range !== undefined && range !== null && range.length > 0)
req.setRequestHeader("Range", "bytes=" + range);
req.onload = function () {
console.log("FRAGMENT DONE LOADING");
sourceBuffer.append(new Uint8Array(req.response));
video.play();
video.currentTime = sourceBuffer.buffered.start(0);
console.log("BUFFERED RANGES --------");
var i, len;
for (i = 0, len = sourceBuffer.buffered.length; i < len; i += 1) {
console.log("RANGE: " + sourceBuffer.buffered.start(i) + " - " + sourceBuffer.buffered.end(i));
}
console.log("------------------------");
}
req.onerror = function () {
alert("Could not load fragment.");
}
req.send();
}
}
function closed() {
alert("MediaSource Closed.");
}
</script>
</head>
<body onload="init()">
<form>
<table style="width: 400px;">
<tr>
<td>mimetype:</td>
<td colspan="2"><input type="text" id="mimetype-source" style="width:93%;" value="video/mp4"/></td>
</tr>
<tr>
<td>codec:</td>
<td colspan="2"><input type="text" id="codec-source" style="width:93%;"/></td>
</tr>
<tr>
<td>initialization:</td>
<td><input type="text" id="init-source" style="width:95%;"/></td>
<td>(range) <input type="text" id="init-range" style="width:60px;"/></td>
</tr>
<tr>
<td>fragment:</td>
<td><input type="text" id="frag-source" style="width:95%;"/></td>
<td>(range) <input type="text" id="frag-range" style="width:60px;"/></td>
</tr>
<tr>
<td colspan="3" style="text-align: center;"><button type="button" onclick="load()">Load</button></td>
</tr>
</table>
</form>
<video controls autoplay width="320" height="240"></video>
</body>
</html>