Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created April 21, 2022 12:03
Show Gist options
  • Select an option

  • Save brianmed/3888bd952323e09b287bd12785451195 to your computer and use it in GitHub Desktop.

Select an option

Save brianmed/3888bd952323e09b287bd12785451195 to your computer and use it in GitHub Desktop.
Example HLS Viewer with hls.js
<html>
<head>
<title>Hls.js demo - basic usage</title>
</head>
<body>
<!-- https://github.com/video-dev/hls.js/releases -->
<script src="dist/hls.js"></script>
<center>
<h1>Hls.js demo - basic usage</h1>
<video height="600" id="video" controls></video>
</center>
<script>
var video = document.getElementById('video');
if (Hls.isSupported()) {
var hls = new Hls({
"lowLatencyMode": true,
});
hls.loadSource('uri.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
video.muted = true;
video.play();
});
}
// hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
// When the browser has built-in HLS support (check using `canPlayType`), we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video element throught the `src` property.
// This is using the built-in support of the plain video element, without using hls.js.
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = 'uri.m3u8';
video.addEventListener('canplay', function () {
video.play();
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment