A Pen by Popardowski on CodePen.
Created
August 20, 2020 08:40
-
-
Save eljabbaryhicham/6ece2b10c03672882327ebca6a896214 to your computer and use it in GitHub Desktop.
Plyr - HLS stream video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<video controls crossorigin playsinline poster="https://bitdash-a.akamaihd.net/content/sintel/poster.png"></video> | |
</div> | |
<!-- Plyr resources and browser polyfills are specified in the pen settings --> | |
<!-- Hls.js 0.9.x and 0.10.x both have critical bugs affecting this demo. Using fixed git hash to when it was working (0.10.0 pre-release), until https://github.com/video-dev/hls.js/issues/1790 has been resolved --> | |
<script src="https://cdn.rawgit.com/video-dev/hls.js/18bb552/dist/hls.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', () => { | |
const source = 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8'; | |
const video = document.querySelector('video'); | |
// For more options see: https://github.com/sampotts/plyr/#options | |
// captions.update is required for captions to work with hls.js | |
const player = new Plyr(video, {captions: {active: true, update: true, language: 'en'}}); | |
if (!Hls.isSupported()) { | |
video.src = source; | |
} else { | |
// For more Hls.js options, see https://github.com/dailymotion/hls.js | |
const hls = new Hls(); | |
hls.loadSource(source); | |
hls.attachMedia(video); | |
window.hls = hls; | |
// Handle changing captions | |
player.on('languagechange', () => { | |
// Caption support is still flaky. See: https://github.com/sampotts/plyr/issues/994 | |
setTimeout(() => hls.subtitleTrack = player.currentTrack, 50); | |
}); | |
} | |
// Expose player so it can be used from the console | |
window.player = player; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6,Array.prototype.includes,CustomEvent,Object.entries,Object.values,URL"></script> | |
<script src="https://unpkg.com/plyr@3"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.container { | |
margin: 20px auto; | |
width: 600px; | |
} | |
video { | |
width: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://unpkg.com/plyr@3/dist/plyr.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment