vue中使用videojs,关闭窗口后视频流一直刷新问题,切换视频流问题

项目开发时遇到问题
使用videojs关闭窗口后视频流也一直刷新,使用pause暂停无效。 实际开发中肯定不能这么消耗内存。
视频是在弹窗的时候展示,所以完整解决方案自己琢磨了一下,如下

    <div v-html="videohtml">
    </div> 

    getVideoDialog() {
      this.videoVisible = true; 
      this.videohtml = `<video id="videoPlayer" class="video-js" style="width:500px;height:330px" muted></video>`;  
      this.$nextTick(() => {
        this.player = Videojs("videoPlayer", this.options);
        ....
      });
    },
    closeVideo() {//关闭窗口方法  
      if (this.player) {  
        this.player.dispose(); // 该方法会重置videojs的内部状态并移除dom
        this.videohtml ='';
      }
      this.videoVisible = false;//注意关闭窗口时间,要在控件销毁之后,否则会有问题
    },

还有一点要注意,v-html里编译出来的dom样式不受style scoped里样式的影响,所以这里大小直接定义在了video上

切换视频流问题
先用了reset后重新load新的地址发现时而切换,不满足需求

 this.player.reset();
 this.player.src([
  {
        src: videoUrl,
        type: "video/x-flv"
      }
    ]);
 this.player.load(videoUrl);
 this.player.play()  

需要调用this.player.dispose(),销毁实例再重新初始化赋值src

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值