forked from videojs/videojs-contrib-eme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
69 lines (59 loc) · 2.21 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>videojs-contrib-eme Demo</title>
<link href="/node_modules/video.js/dist/video-js.css" rel="stylesheet">
</head>
<body>
<video id="videojs-contrib-eme-player" class="video-js vjs-default-skin" controls data-setup='{"plugins": {"eme": {}}}'>
</video>
<ul>
<li><a href="/test/debug.html">Run unit tests in browser.</a></li>
</ul>
<script src="/node_modules/video.js/dist/video.js"></script>
<script src="/dist/videojs-contrib-eme.js"></script>
<script>
(function(window, videojs) {
// Example derived from http://www.html5rocks.com/en/tutorials/eme/basics/#clear-key
const KEY = new Uint8Array([
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
]);
let player = window.player = videojs('videojs-contrib-eme-player');
// Convert Uint8Array into base64 using base64url alphabet, without padding.
let toBase64 = (u8arr) => {
return btoa(String.fromCharCode.apply(null, u8arr)).
replace(/\+/g, '-').replace(/\//g, '_').replace(/=*$/, '');
}
player.src({
src: '/moose_encrypted.webm',
type: 'video/webm',
keySystems: {
'org.w3.clearkey': {
audioContentType: 'audio/webm; codecs="vorbis"',
videoContentType: 'video/webm; codecs="vp8"',
getLicense: (emeOptions, keyMessage, callback) => {
// Parse the clearkey license request.
let request = JSON.parse(new TextDecoder().decode(keyMessage));
// We only know one key, so there should only be one key ID.
// A real license server could easily serve multiple keys.
console.assert(request.kids.length === 1);
let keyObj = {
kty: 'oct',
alg: 'A128KW',
kid: request.kids[0],
k: toBase64(KEY)
};
console.log('Key object:', keyObj);
callback(null, new TextEncoder().encode(JSON.stringify({
keys: [keyObj]
})));
}
}
}
});
}(window, window.videojs));
</script>
</body>
</html>