【发布时间】:2017-06-30 14:37:01
【问题描述】:
我正在使用 videojs 和 videojs-hls 插件来传输 m3u8 文件。在托管 m3u8 文件的后端,存在一些过期逻辑。 x 分钟后,它会抛出一个错误并传播到 videojs 播放器。
如何在调用初始错误处理程序后重新加载 videojs 播放器/事件侦听器?
var player;
function handleErrorEvent() {
console.log('the session expired, show a button to reload videojs');
$('.reload-video-btn').on('click', function() {
// how do I completely reload the videojs player with the same source m3u8 file?
// and ensure that the "ready" and "error" event listener gets called
});
}
function handleVideoReadyEvent() {
player.on('error', handleErrorEvent);
}
function init() {
player = videojs('my-video', {});
player.src({
// this m3u8 file expires after a certain amount of time
src: 'http://localhost:3000/api/stream/stream.m3u8',
type: 'application/x-mpegURL'
});
player.on('ready', handleVideoReadyEvent);
}
init();
【问题讨论】:
标签: javascript video.js