-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
127 lines (107 loc) · 4.6 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
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
<!--
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><a href="https://github.com/cpearce/mse-eme">Fork it on github.</a></div>
<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>
<div id="log">
</div>
<script>
const KEYSYSTEM_TYPE = "org.w3.clearkey";
function Load() {
if (!navigator.requestMediaKeySystemAccess) {
log("EME API is not supported. Enable pref media.eme.enabled to true in about:config");
return;
}
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 options = [];
const audioContentType = 'audio/mp4; codecs="mp4a.40.2"'; // AAC-LC
const videoContentType = 'video/mp4; codecs="avc1.64001F"'; // High profile level 3.1
log('UA: "' + navigator.userAgent + '"');
if (typeof(MediaKeySystemAccess.prototype.getConfiguration) == "undefined") {
// Firefox 43 and earlier used a different style of defining configurations
// for navigator.requestMediaKeySystem that doesn't match the current spec.
log("Detected obsolete navigator.requestMediaKeySystem options style.");
options = [
{
initDataType: "cenc",
videoType: videoContentType,
audioType: audioContentType,
}
];
} else {
options = [
{
initDataTypes: ["cenc"],
videoCapabilities: [{contentType: videoContentType}],
audioCapabilities: [{contentType: audioContentType}],
}
];
}
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, videoContentType, ms, "video", downloadProgress("videoProgress")),
MSELoadTrack(audioFragments, audioContentType, 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>