我是网络技术新手。我有一个由我的api访问的。ts视频,出于安全原因,我需要添加"x-access-token"到我的请求,但真的不怎么。也许你知道?
play(){
if (mpegts.getFeatureList().mseLivePlayback) {
var videoElement = document.getElementById('video-js-node');
var player = mpegts.createPlayer({
type: 'm2ts',
isLive: true,
headers: {'x-access-token': localStorage.getItem('data')},
url: `/my/api/${record}`,
});
player.attachMediaElement(videoElement);
player.load();
player.play();
}
}
我已经阅读了文档(https://github.com/xqq/mpegts.js/blob/master/docs/api.md)并理解了我的错误。代码应该像这样:
play(){
if (mpegts.getFeatureList().mseLivePlayback) {
var videoElement = document.getElementById('video-js-node');
var player = mpegts.createPlayer(
//MediaDataSource
{
type: 'm2ts',
isLive: true,
url: `/my/api/${record}`,
},
//config
{
headers: {
'x-access-token': localStorage.getItem('data')
}
);
player.attachMediaElement(videoElement);
player.load();
player.play();
}
}