videojs m3u8 视频卡顿

videojs m3u8 视频卡顿

问题:

视频在播放一段时间后出现卡顿的现象

文档学习:

https://www.w3school.com.cn/tags/html_ref_audio_video_dom.asp

coding:

<body>
  <style>
    #my-video {
      width: 100%;
      height: 100px;
    }
  </style>
  <video id="my-video" muted autoplay="autoplay" class="video-js vjs-default-skin vjs-big-play-centered myVideo"
    controls>
  </video>
  <script>
    let timer = null
    let src = ".m3u8"//m3u8格式的视频流
   

    var myPlayer = videojs('my-video', {
      autoplay: true,
      muted: true,
      fluid: true,
      controls: true,
      techOrder: ['html5'],
      sources: [{
        type: 'application/x-mpegURL', // m3u8/Hls 的视频流类型
        src: src // 对应播放的m3u8 路径
      }]
    },
      function () {
        // 视频准备好
        var tryTimes = 0;
        var oldSrc = this.src()
        var newSrc = oldSrc.indexOf('?') > -1 ? oldSrc + '&t=' + Date.now() : oldSrc + '?t=' + Date.now()
        this.on('loadedmetadata', function () {
          clearInterval(loaded_timer)
        })
        var seekingTimes = 0;
        var waitingTimes = 0;
        var loaded_timer;
        this.on("error", function () {
          this.src(newSrc);
          this.onload()
          // this.play();
        })
        //每次卡顿都会出发waiting
        this.on('waiting', function () {
          if (waitingTimes > 2) {
            waitingTimes = 0
            myPlayer.src(newSrc);
            this.onload()
          }
        })
      })
  </script>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值