Add custom headers to IMG, VIDEO and AUDIO requests

前端 未结 2 1090
挽巷
挽巷 2021-02-20 15:56

I am working on a project where we need to add some custom headers to the HTTP requests for image, video and audio content in the browser. I\'ve been looking around and not rea

2条回答
  •  名媛妹妹
    2021-02-20 16:14

    As far s I'm aware the only way to do this is with XMLHttpRequest or fetch, BUT you can tried l retrieve binary data for videos and stream it using native stream APIs.

    If the server allows partial requests, which allows you to get a certain amount of bytes only

    You can append the different bytes to a mediasource https://developer.mozilla.org/en-US/docs/Web/API/MediaSource

    I almost got it working

    Although the problem is that mediasource can only deal with fragmented mp4s https://github.com/w3c/media-source/issues/216 https://stackoverflow.com/a/18745164/2016831

    But with some more research it should be possible to manually/automatically fragment the sections of the mp4 video with JavaScript after they're feutched, possibly using ffmpeg.js

提交回复
热议问题