-
-
Save hasinhayder/4f98b5d45b6ef2cc0a210de07afcc63c to your computer and use it in GitHub Desktop.
VideoJS + XHR mod : Adding XHR interceptor
This file contains hidden or 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 media="all" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/video-js.css"> | |
<script src="https://unpkg.com/[email protected]/dist/video.js"></script> | |
<video-js id="player"> | |
<source src="//video/index.m3u8" type="application/x-mpegURL" /> | |
</video-js> | |
<script> | |
var player = videojs("player"); | |
var prefix = "key://"; | |
var urlTpl = "https://domain.com/path/{key}"; | |
// player.ready | |
player.on("loadstart", function (e) { | |
player.tech().hls.xhr.beforeRequest = function(options) { | |
// required for detecting only the key requests | |
if (!options.uri.startsWith(keyPrefix)) { return; } | |
options.headers = options.headers || {}; | |
optopns.headers["Custom-Header"] = "value"; | |
options.uri = urlTpl.replace("{key}", options.uri.substring(keyPrefix.length)); | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://onetdev.medium.com/custom-key-acquisition-for-encrypted-hls-in-videojs-59e495f78e52