使用vue-video-player播放列表循环,同一个video画面中循环播放列表


本文使用vue-video-player组件,实现视频列表循环播放,同一个video画面中,循环播放视频列表,video
中options配置中的sources是数组,可以配置多个视频源,就可以通过代码实现sources列表中的资源进行
循环播放。

说明:转发请注明出处
在这里插入图片描述

安装 vue-video-player

npm i vue-video-player

.vue

<template>
  <div class="hello">
    <video-player ref="videoPlayer" class="vjs-custom-skin" :options="playerOptions" @ended="onPlayerEnded($event)">
    </video-player>
  </div>
</template>
<script>
import 'video.js/dist/video-js.css'
require('vue-video-player/src/custom-theme.css')
import { videoPlayer } from 'vue-video-player'
import videojs from 'video.js'
window.videojs = videojs
require('videojs-contrib-hls/dist/videojs-contrib-hls.js')
export default {
  name: 'HelloWorld',
  components: {
    videoPlayer
  },
  data() {
    return {
      playerOptions: {
        height: '360',
        playbackRates: [0.7, 1, 1.3, 1.5, 1.7],
        //需要循环的列表
        sourcesList: [
          {
            type: "video/mp4",
            src: "http://new.qingdao.gov.cn/masvod/public/2022/03/16/20220316_17f91c9e389_r1_600k.mp4"
          },
          {
            type: "video/mp4",
            src: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4'
          }
        ],
        sources: [
          {
            type: "video/mp4",
            src: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4'
          }
        ],
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 时长显示
          remainingTimeDisplay: true, // 剩下时间
          currentTimeDisplay: true, // 当前时间
          volumeControl: true, // 声音控制键
          playToggle: true, // 暂停和播放键
          progressControl: true, // 进度条
          fullscreenToggle: true // 全屏按钮
        },
        loop: false, //循环列表,这里的loop必须是false
        muted: true,// 是否在不全屏状态下外放声音
        autoplay: true,// 是否浏览器 准备好后自动播放
        isLive: false,// 是否直播
        flash: { hls: { withCredentials: false } },
        poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-5.jpg",
        currentSourceSrc: ''
      }
    }
  },
  mounted() {
    let { sources } = this.playerOptions;
    this.currentSourceSrc = sources.length ? sources[0].src : '';
  },
  methods: {
    // 视频播完回调
    onPlayerEnded(player) {
      let { sourcesList } = player.options_;
      let length = sourcesList.length;
      let currentSourceSrc = ''
      sourcesList.forEach((v, i) => {
        if (this.currentSourceSrc === v.src) {
          let index = i === length - 1 ? 0 : ++i
          console.log(index)
          this.$set(this.playerOptions, 'sources', [sourcesList[index]])
          this.$refs.videoPlayer.player.load()
        }
      })
      this.currentSourceSrc = currentSourceSrc;
    },
  }

}
</script>

说明:播放完一个视频之后,改变sources的内容,然后重新播放,在这里需要调用player.load(),而不是player.play()

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值