解决 使用video.js封装video 多视频源时 改变sources的src无效的问题

解决 使用video.js封装video 多视频源时 改变sources的src无效的问题

video-player 组件

<template>
  <div>
    <video ref="videoPlayer" class="video-js"></video>
  </div>
</template>

<script>
import 'video.js/dist/video-js.css';
import videojs from 'video.js';
export default {
  name: "video-player",
  props: {
    options: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      player: null
    }
  },
  methods: {
    show(data) {
      this.player.src(data)
    }
  },
  mounted() {
    this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {
      console.log('onPlayerReady', this);
    })
  },
  beforeDestroy() {
    console.log('beforeDestroy')
    if (this.player) {
      this.player.dispose()
    }
  }
}
</script>

<style scoped>
</style>

需要播放视频的页面

      <el-dialog :visible.sync="show_video">
        <div class="video-box">
          <div class="video">
            <video-player :options="videoOptions" class="video-css" ref="video" />
          </div>
        </div>
      </el-dialog>

      //  data
      videoOptions: {
        controls: true,//开启交互,即是用户可控。
        muted: true,//开启视频时是否静音
        fluid: true,//根据外层css样式大小,自动填充宽高!比较实用,可搭配响应式
        reload: "auto",//重载
        //其余设置根据需求添加!
        poster: '',//视频封面
        sources: [//视频播放源,建议本地
          {
            src: '',
            type: "video/mp4"
          },
        ]
      }

        // methods
        this.show_video = true
        // 必须调用this.player.src 方法 多视频源时只改变sources的src无效
        this.videoOptions.sources[0].src = 'xxx.mp4'    // 你的视频源
        this.$refs.video.show('xxx.mp4')  


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值