hls播放m3u8 添加header请求头,在请求ts的url上添加参数
2023-04-18 23:54:25
1232 次阅读
0 个评论
使用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 github文档地址
https://github.com/video-dev/hls.js/blob/master/docs/API.md#xhrsetup
- 0回答
- 1粉丝
- 0关注