Shaka player EntDrm
by Miha Nagelj
HTML
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/shaka-player.compiled.min.js"></script>
<video id="video"
width="640"
poster="//shaka-player-demo.appspot.com/assets/poster.jpg"
controls autoplay></video>
<script src=https://cdn.jsdelivr.net/npm/[email protected]/dist/shaka-player.compiled.min.js></script>
JavaScript
const manifestUri =
'https://vz-0dcf3ca7-468.b-cdn.net/25f5b2ef-5663-4336-9b4b-6cf2f6e6cc1c/playlist.m3u8';
function initApp() {
// 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()) {
// Everything looks good!
initPlayer();
} else {
// This browser does not have the minimum set of APIs we need.
console.error('Browser not supported!');
}
}
async function initPlayer() {
// Create a Player instance.
const video = document.getElementById('video');
const player = new shaka.Player();
player.configure({
drm: {
servers: {
'com.widevine.alpha': 'https://video.bunnycdn.com/WidevineLicense/196366/25f5b2ef-5663-4336-9b4b-6cf2f6e6cc1c?contentId=25f5b2ef-5663-4336-9b4b-6cf2f6e6cc1c'
}
}
});
await player.attach(video);
// Attach player to the window to make it easy to access in the JS console.
window.player = player;
// Listen for error events.
player.addEventListener('error', onErrorEvent);
// Try to load a manifest.
// This is an asynchronous process.
try {
await player.load(manifestUri);
// This runs if the asynchronous load is successful.
console.log('The video has now been loaded!');
} catch (e) {
// onError is executed if the asynchronous load fails.
onError(e);
}
}
function onErrorEvent(event) {
// Extract the shaka.util.Error object from the event.
onError(event.detail);
}
function onError(error) {
// Log the error.
console.error('Error code', error.code, 'object', error);
}
document.addEventListener('DOMContentLoaded', initApp);