1. 介紹
正常的 m3u8 格式視頻通過控制臺是無法下載的,但是可以通過插件下載,下面介紹如何規(guī)避這個問題。
思路:后端生成一個一次性的密鑰,前端放在請求頭中,可以防止大部分插件下載。這里只說前端。文章來源:http://www.zghlxwxcb.cn/news/detail-820418.html
2. 實(shí)現(xiàn)
集成 DPlayer 播放器這里就不說了,網(wǎng)上一大推。文章來源地址http://www.zghlxwxcb.cn/news/detail-820418.html
// 接口封裝
disposable() {
return new Promise((resolve, reject) => {
axios.get('file/disposable').then(res => {
resolve(res);
}).catch(err => {
reject(err);
});
});
},
// m3u8
let that = this;
this.dplayer = new DPlayer({
container: document.getElementById('page-content-view-video'),
autoplay: true,
hotkey: true,
video: {
url: 'http:xxxx.m3u8',
type: 'customHls',
customType: {
customHls: function(video, player) {
let config = {
xhrSetup: async function(xhr, url) {
// 這里是為了每個請求攜帶不同的一次性密鑰
if(url.endsWith('.m3u8')) {
xhr.setRequestHeader('disposable', await that.$api.disposable());
}else if(url.endsWith('.ts')) {
xhr.setRequestHeader('disposable', await that.$api.disposable());
}
},
};
const hls = new window.Hls(config);
hls.loadSource(video.src);
hls.attachMedia(video);
},
}
},
});
到了這里,關(guān)于DPlayer m3u8 視頻禁止下載的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!