hls播放m3u8 添加header请求头,在请求ts的url上添加参数

找了很久没有找到相关的方法,无赖自己研究hls,终于搞定,分享一下吧

使用hls xhr配置项 xhrSetup 方法添加请求头

 const Hls = new Hls({ fragLoadingTimeOut: 2000 });

    Hls.on(Hls.Events.MEDIA_ATTACHED, () => {
       // M3U8 播放地址 props.src
      Hls.loadSource(props.src);
      Hls.config.xhrSetup = (xhr, url) => {
        // 请求ts的url 添加参数 props.fileid
        url = url + "?t=" + props.fileid;
        // 这一步必须 告诉hls重新发送ts请求
        xhr.open("GET", url, true);

        // header 添加参数
        xhr.setRequestHeader("token", props.token);
        xhr.setRequestHeader("initiatorIndex", props.initiatorIndex);
      };
    });

附上hls git地址

 hls github地址:https://github.com/video-dev/hls.js/blob/master/docs/API.md#xhrsetuphttps://github.com/video-dev/hls.js/blob/master/docs/API.md#xhrsetup

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值