flv.js解决流延迟、断流问题

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);
        }
      });

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杰姆小生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值