-
Notifications
You must be signed in to change notification settings - Fork 21
/
crash1.html
108 lines (88 loc) · 3.67 KB
/
crash1.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
<!--
Copyright 2014, Mozilla Foundation and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title>MSE + EME Demo</title>
<style>
#log {
font-size: small;
}
video {
max-width: 100%;
}
h1 {
font-family: arial;
font-size: large;
}
</style>
<script type="text/javascript" src="resources.js"></script>
<script type="text/javascript" src="eme.js"></script>
<script type="text/javascript" src="mse.js"></script>
</head>
<body>
<a href="https://github.com/cpearce/mse-eme"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<h1>Media Source Extensions + ClearKey Encrypted Media Extension Demo</h1>
<div>Video downloaded: <span id="videoProgress">0</span>%</div>
<div>Audio downloaded: <span id="audioProgress">0</span>%</div>
<video id="v" controls preload="auto">
</video>
<br>
<button onclick="Load();">Reload</button>
<div id="log">
</div>
<script>
const KEYSYSTEM_TYPE = "org.w3.clearkey";
function Load() {
var video = e("v");
// Log events dispatched to make debugging easier...
[ "canplay", "canplaythrough", "encrypted", "ended", "error", "loadeddata",
"loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
"stalled", "suspend", "waiting",
].forEach(function (e) {
v.addEventListener(e, function(event) {
log("EVENT: " + e);
}, false);
});
var keys = {
// "keyid" : "key"
"7e571d037e571d037e571d037e571d03" : "7e5733337e5733337e5733337e573333",
"7e571d047e571d047e571d047e571d04" : "7e5744447e5744447e5744447e574444",
};
var options = [
{
initDataType: "cenc",
videoType: "video/mp4",
}
];
SetupEME(video, KEYSYSTEM_TYPE, "video", keys, options);
var ms = new MediaSource();
video.src = URL.createObjectURL(ms);
function downloadProgress(id) {
return function(percent) {
e(id).innerHTML = percent;
}
}
var SourceOpen = function () {
ms.removeEventListener("sourceopen", SourceOpen);
log(name + " sourceopen");
Promise.all([MSELoadTrack(videoFragments, "video/mp4", ms, "video", downloadProgress("videoProgress")),
MSELoadTrack(audioFragments, "audio/mp4", ms, "audio", downloadProgress("audioProgress"))])
.then(function(){log("All segments downloaded"); ms.endOfStream();});
}
ms.addEventListener("sourceopen", SourceOpen);
video.addEventListener("canplay", function(){video.play();});
}
Load();
</script>
</body>
</html>