Skip to content

Instantly share code, notes, and snippets.

@SunRed
Last active October 4, 2022 11:21
Show Gist options
  • Save SunRed/a8082d466c4b38646b72ab6f23431733 to your computer and use it in GitHub Desktop.
Save SunRed/a8082d466c4b38646b72ab6f23431733 to your computer and use it in GitHub Desktop.
Simple video player using Plyr and Shaka Player from Google
<!DOCTYPE html>
<html lang="en">
<head>
<title>Player</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.7.2/plyr.min.css" integrity="sha512-1EV4ofS7XcLAlzTrHHfhk7UzxVEY8Qog2Jeve5UhGYrFm2BQylunV46RXUa5JJilEAmIAtIA2KbFxISjVmw+zg==" crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.2.1/controls.min.css" integrity="sha512-+8BR6lbGCJm021MhjZMszue47HrhbLww8rZqeelgkqAgTWsWvYe7m8/H7V9lUVrPDI18vxBTdJogoxVPBB3Qjg==" crossorigin="anonymous" referrerpolicy="no-referrer">
<style>
* {
margin: 0;
padding: 0;
}
html, body, .plyr {
height: 100%;
}
.container {
margin: 0 auto;
width: 100%;
height: 100%;
}
body {
font-family: sans-serif;
background: #000;
color: #bbb;
}
p {
margin: 10px;
}
.plyr__controls .plyr__controls__item:first-child {
margin-right: 0;
}
.plyr__controls .plyr__controls__item:nth-child(2) {
margin-right: auto;
}
.plyr__controls .plyr__volume {
max-width: 120px;
}
#video-container {
--plyr-color-main: #4d505f;
}
</style>
<body>
<div id="video-container" class="container">
<video controls playsinline></video>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.7.2/plyr.min.js" integrity="sha512-5c+ic1AaqQ73rhjELeXI19EFx9KWd/LPFZ91ztP4x+MaufkHnpSEuLHcE6KwGn6G6I+ScYkSPONmrdGQh1GjiA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.2.1/shaka-player.compiled.min.js" integrity="sha512-3sCZhddgbq6xVaKCACA788A7VoVwgiNAIEtGQvEw3ZPKFSU4t5PCuCthBTJbYhYCmMFlSB2sjz2lIyVOxYyZug==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.2.1/shaka-player.ui.min.js" integrity="sha512-6uxI+6Hmr7/Vf/49GbFtQWmhq0FzdXTr4ToaviZhPPSYytfPvl1LoXQdsWK69xPjPVOIZImk6TDXj3zlrHQzRQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const video = document.querySelector('video');
shaka.polyfill.installAll();
if (shaka.Player.isBrowserSupported()) {
shaka.Player.probeSupport().then(support => {
const source = support.manifest.mpd ?
'/player/dash/' + location.pathname.substr(8).replace(".html", ".mpd") :
'/player/hls/' + location.pathname.substr(8).replace(".html", ".m3u8");
const player = new Plyr(video, {
controls: ['play-large', 'play', 'mute', 'volume', 'settings', 'pip', 'fullscreen'],
settings: ['speed']
});
window.player = player;
const shakaInstance = new shaka.Player(video);
shakaInstance.load(source);
});
} else {
console.warn('Browser is not supported!');
const elem = document.createElement("p");
elem.appendChild(document.createTextNode("Browser not supported ¯\\_(ツ)_/¯"));
document.getElementById("video-container").appendChild(elem);
video.remove();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment