-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathclose-session.html
128 lines (106 loc) · 4.51 KB
/
close-session.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
<!--
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;
}
p.red {
font-family: arial;
background-color: red;
}
</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>
<p class="red">Note: E10S (multi-process Firefox) must be DISABLED for EME to work.</p>
<p>To disable E10S, click hamburger menu ("≡") on Firefox's toolbar, Options, and uncheck "Enable E10S (multi-process)", and restart Firefox.
</p>
<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 id="loadButton" onclick="Load();">Load</button>
<br>
<button id="closeSessionsButton">Close Sessions</button>
<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 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;
}
}
function closeSessions() {
for (var i = 0; i < video.sessions.length; i++) {
video.sessions[i].close();
}
}
e('closeSessionsButton').addEventListener('click', closeSessions);
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();});
}
</script>
</body>
</html>