找了很久没有找到相关的方法,无赖自己研究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地址