视频打点videojs和videojs-markers实现(vue+element)

7 篇文章 0 订阅

<template>
  <div class="homePageContainer">
    <div>
      <video ref="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered"></video>
      <el-button @click="onPrev">上一节</el-button>
      <el-button @click="onNext">下一节</el-button>
    </div>
  </div>
</template>

<script>
// npm install video.js --save
// npm install videojs-markers --save
import "videojs-markers/dist/videojs.markers.min.css";
import videojs from 'video.js'
import 'video.js/dist/video-js.css'
import 'videojs-markers'
export default {
  data() {
    return {
      options: {
        autoplay: 'muted',//自动播放
        height: 500,
        width: 800,
        controls: true,//用户可以与之交互的控件
        loop:true,//视频一结束就重新开始
        muted:false,//默认情况下将使所有音频静音
        playsinline: true,
        webkitPlaysinline: true,
        // aspectRatio:"16:9",//显示比率
        playbackRates: [0.5, 1, 1.5, 2],
        fullscreen:{
          options: {navigationUI: 'hide'}
        },
        sources: [
          {
            src: 'http://vjs.zencdn.net/v/oceans.mp4',
            type: "video/mp4"
          },
        ]
      },
      player: null
    }
  },
  mounted() {
    this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {
      console.log('onPlayerReady', this);
    })
    // 设置标点
    this.player.markers({
      // 不显示鼠标悬浮标记提示文字
      markerTip: {
        display: false
      },
      markerStyle: {
        'width':'7px',
        'background-color': 'red',
        'border-radius': '50%',
      },
      markers: [
        {
          time: 0.694313,
          class: 'custom-marker-class'
        },
        {
          time: 5.694313,
          class: 'custom-marker-class'
        },
        {
          time: 10.694313,
          class: 'custom-marker-class'
        },
        {
          time: 15.694313,
          class: 'custom-marker-class'
        }
      ]
    });
    // 获取当前播放时间
    this.player.on("timeupdate", function(event) {
      console.log(this.currentTime());
    });
  },
    methods: {
      onPrev () {
        this.player.markers.prev()
      },
      onNext() {
        this.player.markers.next()
      }
    },
    beforeDestroy() {
      if (this.player) {
        this.player.dispose()
      }
    },
};
</script>

<style lang="scss">
.homePageContainer {
  padding: 0px 20px 20px 20px;
}
</style>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值