DRM and AES-128 encryption
Tip: open your browser's developer console and use the player and THEOplayer variables to interact with this demo.
| Selected stream | - |
|---|---|
| Key systems in this browser | Widevine: …, PlayReady: …, FairPlay: … |
This example plays protected content:
- DRM: an HLS stream protected with Widevine, PlayReady and FairPlay. The player uses the key system that the current browser supports: Widevine or PlayReady in most browsers, and FairPlay in Safari. The license requests are handled by the Axinom DRM integration.
- AES-128: an HLS stream encrypted with AES-128. The player fetches the decryption key from the URL in the HLS playlist, so no extra configuration is needed.
The box below the player shows which stream the player is playing, and which DRM key systems your browser supports.
Code
demo.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>DRM and AES-128 encryption</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet" />
<style>
html,
body {
margin: 0;
padding: 0;
}
theoplayer-default-ui:not(:defined) {
display: inline-block;
box-sizing: border-box;
}
theoplayer-default-ui {
width: 100%;
aspect-ratio: 16 / 9;
font-family: 'Noto Sans', sans-serif;
background: #000;
}
</style>
<script src="https://cdn.theoplayer.com/dash/theoplayer/THEOplayer.js"></script>
<script nomodule src="https://unpkg.com/@theoplayer/web-ui@2/polyfills"></script>
<script async src="https://unpkg.com/@theoplayer/web-ui@2"></script>
</head>
<body>
<!--
libraryLocation: For demonstration purposes, we use the theoplayer.com CDN.
For production use, we recommend hosting THEOplayer yourself
and changing this (as well as the <script> tags above)
to point to THEOplayer's location on your own website.
licenseUrl: Change this to point to your THEOplayer license file.
Alternatively, replace it with a "license" property whose value is your THEOplayer license itself.
-->
<theoplayer-default-ui
configuration='{"libraryLocation":"https://cdn.theoplayer.com/dash/theoplayer/","licenseUrl":"../../../../theoplayer-license.txt","mutedAutoplay":"all"}'
></theoplayer-default-ui>
<script src="../utils.js"></script>
<script>
// A test token for the Axinom license servers.
const axinomToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJ2ZXJzaW9uIjogMSwKICAiY29tX2tleV9pZCI6ICI2OWU1NDA4OC1lOWUwLTQ1MzAtOGMxYS0xZWI2ZGNkMGQxNGUiLAogICJtZXNzYWdlIjogewogICAgInR5cGUiOiAiZW50aXRsZW1lbnRfbWVzc2FnZSIsCiAgICAidmVyc2lvbiI6IDIsCiAgICAibGljZW5zZSI6IHsKICAgICAgImFsbG93X3BlcnNpc3RlbmNlIjogdHJ1ZQogICAgfSwKICAgICJjb250ZW50X2tleXNfc291cmNlIjogewogICAgICAiaW5saW5lIjogWwogICAgICAgIHsKICAgICAgICAgICJpZCI6ICIzMDJmODBkZC00MTFlLTQ4ODYtYmNhNS1iYjFmODAxOGEwMjQiLAogICAgICAgICAgImVuY3J5cHRlZF9rZXkiOiAicm9LQWcwdDdKaTFpNDNmd3YremZ0UT09IiwKICAgICAgICAgICJ1c2FnZV9wb2xpY3kiOiAiUG9saWN5IEEiCiAgICAgICAgfQogICAgICBdCiAgICB9LAogICAgImNvbnRlbnRfa2V5X3VzYWdlX3BvbGljaWVzIjogWwogICAgICB7CiAgICAgICAgIm5hbWUiOiAiUG9saWN5IEEiLAogICAgICAgICJwbGF5cmVhZHkiOiB7CiAgICAgICAgICAibWluX2RldmljZV9zZWN1cml0eV9sZXZlbCI6IDE1MCwKICAgICAgICAgICJwbGF5X2VuYWJsZXJzIjogWwogICAgICAgICAgICAiNzg2NjI3RDgtQzJBNi00NEJFLThGODgtMDhBRTI1NUIwMUE3IgogICAgICAgICAgXQogICAgICAgIH0KICAgICAgfQogICAgXQogIH0KfQ._NfhLVY7S6k8TJDWPeMPhUawhympnrk6WAZHOVjER6M';
const sources = {
// HLS with AES-128 encryption: no extra configuration is needed.
aes: {
sources: {
src: 'https://cdn.theoplayer.com/video/big_buck_bunny_encrypted/stream-800/index.m3u8',
type: 'application/x-mpegurl',
},
poster: 'https://cdn.theoplayer.com/video/big_buck_bunny/poster.jpg',
metadata: { title: 'Big Buck Bunny (AES-128)' },
},
// A single HLS (CMAF) stream protected with Widevine, PlayReady and FairPlay.
// The player uses the key system that is supported by the current browser.
drm: {
sources: {
src: 'https://media.axprod.net/TestVectors/Cmaf/protected_1080p_h264_cbcs/manifest.m3u8',
type: 'application/x-mpegurl',
contentProtection: {
integration: 'axinom',
token: axinomToken,
widevine: {
licenseAcquisitionURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
},
playready: {
licenseAcquisitionURL: 'https://drm-playready-licensing.axtest.net/AcquireLicense',
},
fairplay: {
licenseAcquisitionURL: 'https://drm-fairplay-licensing.axtest.net/AcquireLicense',
certificateURL: 'https://vtb.axinom.com/FPScert/fairplay.cer',
},
},
},
metadata: { title: 'Axinom test vector (Widevine, PlayReady or FairPlay)' },
},
};
const ui = document.querySelector('theoplayer-default-ui');
ui.source = sources.drm;
onPlayerReady((player) => {
function reportState(error) {
sendToParent('drm', { src: player.src, error: error && { code: error.code, message: error.message } });
}
player.addEventListener(['sourcechange', 'loadedmetadata'], () => reportState());
player.addEventListener('error', (event) => reportState(event.errorObject));
onParentMessage('drm-source', ({ name }) => {
player.autoplay = true;
player.source = sources[name];
});
reportState();
});
</script>
</body>
</html>