5
<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?

Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
Benjamin W
  • 2,658
  • 7
  • 26
  • 48

1 Answers1

7

try to use xhrSetup.

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