Vue2项目视频控件大全,亲测有效

HTML部分

<div class="fl">
        <div class="video-box">
          <div v-for="(video, index) in videoList" :key="index">
            <video
              style="width: 100%; height: 300px"
              :id="'video' + index"
              ref="videoElement"
              controls
              autoplay
              muted
            ></video>
          </div>
        </div>
        <div style="display: flex; width: 1000px" class="mt">
          <el-button @click="playOrPauseBtn">
            <i class="el-icon-video-play" v-if="playOrPause">播放</i>
            <i class="el-icon-video-pause" v-else>暂停</i>
          </el-button>
          <el-button @click="backTwentySeconds">后退20秒</el-button>
          <el-button @click="backTenSeconds">后退10秒</el-button>
          <el-button @click="backFiveSeconds">后退5秒</el-button>
          <el-button @click="slowPlayback">减速播放</el-button>
          <el-button @click="oneXSpeed">1X</el-button>
          <el-button @click="twoXSpeed">2X</el-button>
          <el-button @click="threeXSpeed">3X</el-button>
          <el-button @click="fourXSpeed">4X</el-button>
          <el-button @click="fiveXSpeed">5X</el-button>
          <el-button @click="sixXSpeed">6X</el-button>
          <el-button @click="sevenXSpeed">7X</el-button>
          <el-button @click="eightXSpeed">8X</el-button>
        </div>
      </div>

script部分

data(){
          return {
              playOrPause: false,
          }
      }
      mounted(){
              setInterval(() => {
      this.playcomplete();
    }, 5000);
      }
      methods:{
             //播放或暂停
    playOrPauseBtn() {
      const videoElement = this.$refs.videoElement;
      console.log(this.playOrPause);
      if (this.playOrPause) {
        videoElement.forEach((v) => {
          v.play();
        });
        this.playOrPause = !this.playOrPause;
      } else {
        videoElement.forEach((v) => {
          v.pause();
        });
        this.playOrPause = !this.playOrPause;
      }
    },
    // 后退20秒
    backTwentySeconds() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.currentTime -= 20;
      });
    },
    // 后退10秒
    backTenSeconds() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.currentTime -= 10;
      });
    },

    // 后退5秒
    backFiveSeconds() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.currentTime -= 5;
      });
    },
     //同步播放
    simulcast() {
      const videoElement = this.$refs.videoElement;
      videoElement[0].currentTime = videoElement[1].currentTime;
    },
      //判断是否播放完毕
    playcomplete() {
      // debugger;
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        if (v.currentTime >= v.duration) {
          //  this.videoEnd = true;
          this.playOrPause = true;
          console.log("播放完毕");
         
        } else if (v.currentTime >= v.duration && this.playOrPause) {
          this.playOrPause = false;
          // this.videoEnd = false;
          console.log("播放中");
        }
      });
    },
    //减速播放
    slowPlayback() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        if (v.playbackRate * 10 > 2) {
          v.playbackRate = (v.playbackRate * 10 - 2) / 10;
        }
      });
    },

    //1X
    oneXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 1;
      });
    },
    //2X
    twoXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 2;
      });
    },
    //3X
    threeXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 3;
      });
    },
    //4X
    fourXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 4;
      });
    },
    //5X
    fiveXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 5;
      });
    },
    // 6X
    sixXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 6;
      });
    },
    // 7X
    sevenXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 7;
      });
    },
    // 8X
    eightXSpeed() {
      const videoElement = this.$refs.videoElement;
      videoElement.forEach((v) => {
        v.playbackRate = 8;
      });
    },
      }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值