Created
September 9, 2022 05:04
-
-
Save rahul-yr/5d96a53949687d7b8586f9d000a12dfd to your computer and use it in GitHub Desktop.
Stream HLS Videos using plain HTML - Along with custom request headers to Video.js
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> | |
<title>Document</title> | |
</head> | |
<body> | |
<video id="video" width="640" height="400" controls="controls"></video> | |
<script> | |
if (Hls.isSupported()) { | |
var video = document.getElementById('video'); | |
var hls = new Hls({ | |
xhrSetup: xhr => { | |
xhr.setRequestHeader('x-custom-access-token', "21232f297a57a5a743894a0e4a801fc3"); | |
} | |
}); | |
var url2 = 'http://localhost:8080/media/hls/vimeo.m3u8'; | |
hls.loadSource(url2); | |
hls.attachMedia(video); | |
hls.on(Hls.Events.MANIFEST_PARSED, function () { | |
video.play(); | |
}); | |
} else { | |
console.log("HLS not supported"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment