简体   繁体   中英

HLS.js required send http header

<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>

<video id="video" controls></video>

<script>
if (Hls.isSupported()) {
  const video = document.getElementById('video');
  const hls = new Hls();
  hls.attachMedia(video);

  hls.on(Hls.Events.MEDIA_ATTACHED, function () {
    hls.loadSource("http://foo.com/abc.m3u8");
  });

}
</script>


http header
id: 123
token: 456

I have a video required links to API, this API required to send id & token from HTTP header.

Does anyone know how to add HTTP header into HLS.js?

try to use xhrSetup .

 const hls = new Hls({ xhrSetup: xhr => { xhr.setRequestHeader('id', 1) xhr.setRequestHeader('token', 456) } }) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM