前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >videojs实际应用

videojs实际应用

作者头像
tianyawhl
发布2022-08-07 14:39:40
1.9K0
发布2022-08-07 14:39:40
举报
文章被收录于专栏:前端之攻略前端之攻略

一个页面一个video,点击切换显示不同的画面

代码语言:javascript
复制
<div v-html="videoHtml">

</div>
代码语言:javascript
复制
    initVideo(){
      this.videoHtml = '<video ref="videotest" id="video" width="865" height="460" preload="auto" class="video-js" controls></video>'
      this.$nextTick(()=>{
          let option = {
            bigPlayButton:true,
            textTrackDisplay:false,
            posterImage:true,
            errorDisplay:false,
            controlBar:true,
            autoplay:true,
            // loop:true,//循环:boolean
            muted:true,
            sources:[{
              // src:"http://192.168.30.65:7086/live/cameraid/1000004%240/substream/2.m3u8",
              src:this.videoUrl,
              type:"application/x-mpegURL"
            }]
          }
          this.player = videojs("video",option)          
      })
    }, 
代码语言:javascript
复制
    changeVideo(obj,index) {
      console.log(obj, "obj");
      let url = obj[1].value;
      this.curCameriaId = index
      if(this.player){
        this.player.dispose()
        this.videoHtml = ""
      }
      this.videoUrl = url;
      this.$nextTick(()=>{  // 要写this.$nextTick 否则会报错
          this.initVideo()
      })
    },

一个页面同时显示多个video

代码语言:javascript
复制
<!-- 多个摄像头情况 -->
<div v-for="(item,index) in videoUrlList" :id="'videoWrap'+index" :key="index" style="width:640px;height:460px;margin-bottom:10px;">

</div>
代码语言:javascript
复制
    initVideoTest(){
      setTimeout(() => {
      this.videoUrlList.map((item,index)=>{
        let videoHtml = `<video ref="videotest" id="video${index}" width="640" height="460" preload="auto" class="video-js" controls></video>`
        document.getElementById("videoWrap"+index).innerHTML = videoHtml
        this.$nextTick(()=>{
          let option = {
            bigPlayButton:true,
            textTrackDisplay:false,
            posterImage:true,
            errorDisplay:false,
            controlBar:true,
            autoplay:true,
            // loop:true,//循环:boolean
            muted:true,
            sources:[{
              // src:"http://192.168.30.665:7086/live/cameraid/1000001%240/substream/2.m3u8",
              src:item,
              type:"application/x-mpegURL"
            }]
          }
         this['player'+index] = videojs("video"+index,option)
      
        })        
      })        
      }, 500);
    },

注意退出的时候要销毁

代码语言:javascript
复制
    closeCamearDialog() {
      if(this.player){
        this.player.dispose()
        this.videoHtml = ""
      }
      // 多个摄像头的情况  
      // this.videoUrlList.forEach((item,index)=>{
      //   this['player'+index].dispose()
      // })
      this.cameraData = this.$options.data().cameraData;
    },
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-08-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档