1、前端更具需求下载flv.js插件 FLV.JS
2、延迟
setInterval(() => {
if (this.player.buffered.length) {
let end = this.player.buffered.end(0);//获取当前时间值
let diff = end - this.player.currentTime;//获取相差差值
if (diff >= 1) {//如果差值大于等于0.5 手动跳帧 这里可根据自身需求来定
this.player.currentTime = this.player.buffered.end(0);//手动跳帧
}
}
}, 5000); //5000毫秒执行一次
注释:currentTime不要直接指定end(0),用this.player.buffered.end(0) - n。(n为自己当前时间前n秒)
3、断流
this.player.on(flvjs.Events.ERROR, (errorType, errorDetail, errorInfo) => {
console.log("类型:"+errorType,"报错内容"+errorDetail,"报错信息"+errorInfo);
//视频报错,销毁之后重新创建
if (this.player) {
this.player.pause();
this.player.unload();
this.player.detachMediaElement();
this.player.destroy();
this.player= null;
this.createPlayer(videoElement, this.url);
}
});