-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidevine.js
71 lines (61 loc) · 2.08 KB
/
widevine.js
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
window.manifestURL = 'https://d384padtbeqfgy.cloudfront.net/transcoded/8eaHZjXt6km/video.mpd';
function setUp() {
// Install built-in polyfills to patch browser incompatibilities.
shaka.polyfill.installAll();
// Check to see if the browser supports the basic APIs Shaka needs.
if (shaka.Player.isBrowserSupported()) {
setupPlayer();
} else {
console.error('The Browser, you are using does not support Shaka Player!');
}
// Update the online status and add listeners so that we can visualize
// our network state to the user.
updateOnlineStatus();
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
}
function setupPlayer() {
var video = document.getElementById('video');
var player = new shaka.Player(video);
// Attach player to the window to make it easy to access in the browser console.
window.player = player;
// Listen for errors.
player.addEventListener('error', onErrorEvent);
player.configure({
drm: {
servers: {
'com.widevine.alpha': WIDEVINE_LICENSE_URL,
},
},
});
player.getNetworkingEngine().registerRequestFilter(function (type, request) {
if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) {
console.log("Player license interceptor")
request.headers['Content-type'] = 'application/octet-stream';
}
});
}
async function load() {
// Try to load a manifest.
// This is an asynchronous process.
try {
await window.player.load(window.manifestURL);
// This runs if the asynchronous load is successful.
console.log('The video has now been loaded!');
} catch (exception) {
// shakaOnError is executed if the asynchronous load fails.
onError(exception);
}
}
function onErrorEvent(event) {
// Extract the shaka.util.Error object from the event.
onError(event.detail);
}
function onError(error) {
alert(error);
console.error('Error code', error.code, 'object', error);
if (window.player) {
window.player.detach();
}
}
setUp();