能力一般水平有限,自己真的不是做前端的料啊,奈何两手抓,两手都要硬啊。求各位大神路过的时候指点一下,感激不尽。
需求就是,多路视频同步播放,需要实现一键播放、暂停、快播(当然不是那个快播)、慢播,同时还需要统一的外部进度条控制。因为实在不知道标准的解决方案是什么,项目需求也比较急,所以只能自己大概先写一个能够满足基本需求的,后续再修改。
上代码,vue + element-ui

<template>
  <div class="app-container">
    <div class="data-container">

      <div style="clear:both;text-align:center" :hidden=videoHidden class="videoPlay">
        <div style="display:inline" v-for="videoObj in videoList"
             :key="videoObj.sequence"
             :label="videoObj.sequence"
             :value="videoObj.url">
          <video controls="controls" :width=width :id=videoObj.sequence preload="auto" :src=videoObj.url>
          </video>
        </div>
        <div class="controls">
          <el-select v-model=playSpeed value-key="id" placeholder="播放速度" clearable filterable style="width:120px">
            <el-option
              v-for="item in playSpeedList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-button type="primary" icon="el-icon-caret-right" @click="start()">{{'播放'}}</el-button>
          <el-button type="primary" @click="pause()">{{'暂停'}}</el-button>
          <el-time-picker
            v-model="time"
            :picker-options="{selectableRange: '00:00:00 - 02:59:59'}"
            style="width:120px"
            arrow-control
            value-format="HH:mm:ss"
            :editable=true
            placeholder="请选择">
          </el-time-picker>
          <el-button type="primary" @click="seek_to()">{{'跳转'}}</el-button>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
  export default {
    name: 'VideoPlayer',
    data() {
      return {
        playSpeedList: [{
          value: 0.5,
          label: '0.5倍'
        }, {
          value: 0.75,
          label: '0.75倍'
        }, {
          value: 1,
          label: '正常'
        }, {
          value: 1.25,
          label: '1.25倍'
        }, {
          value: 1.5,
          label: '1.5倍'
        }, {
          value: 2,
          label: '2倍'
        }],
        videoHidden: true,
        videoList: [],
        width: '100%',
        time: new Date(1994, 1, 17, 0, 0, 0),
        playSpeed: 1
      }
    },
    created() {
      this.videoList = this.$route.query.videoList
      this.videoHidden = false
      if (this.videoList.length === 1) {
        this.width = '100%'
      } else if (this.videoList.length >= 2 && this.videoList.length <= 4) {
        this.width = '50%'
      } else if (this.videoList.length >= 5 && this.videoList.length <= 9) {
        this.width = '33.3%'
      } else if (this.videoList.length > 9) {
        this.width = '25%'
      }
    },
    methods: {
      start() {
        for (var i = 0; i < this.videoList.length; i++) {
          var video = document.getElementById(this.videoList[i].sequence)
          video.play()
          video.playbackRate = this.playSpeed
        }
      },
      pause() {
        for (var i = 0; i < this.videoList.length; i++) {
          var video = document.getElementById(this.videoList[i].sequence)
          video.pause()
        }
      },
      seek_to() {
        for (var i = 0; i < this.videoList.length; i++) {
          var video = document.getElementById(this.videoList[i].sequence)
          if (this.time.toString().indexOf('00:00:00') !== -1) {
            video.currentTime = 0
          } else {
            var timeArr = this.time.split(':')
            video.currentTime = parseFloat(timeArr[0] * 3600 + timeArr[1] * 60 + timeArr[2] * 1)
          }
          if (video.paused) {
            video.pause()
          } else {
            video.play()
          }
        }
      }
    }
  }

</script>

<style>
</style>

界面效果如图,基本满足了需求,后续就是要将跳转改为播放进度条了,加油吧。
多路同步播放器

相关文章:

  • 2021-08-03
  • 2022-02-03
  • 2021-08-31
  • 2021-07-25
  • 2022-12-23
  • 2021-12-15
  • 2021-12-18
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-01-17
  • 2021-12-31
相关资源
相似解决方案