<template>
    <div>
        <video ref="videoRef"></video>
    </div>
</template>
<script>
import videojs from 'video.js';

export default {
    name: "videoRef",
    props: {
        options: {
            type: Object,
            default() {
                return {};
            }
        }
    },
    data() {
        return {
            player: null
        }
    },
    mounted() {
        this.player = videojs(this.$refs.videoRef, this.options, function onPlayerReady() {
            console.log('onPlayerReady', this);
        })
        //每次时间更新的时候调用该方法
        this.player.on('timeupdate', ()=> {
          var currentTime = this.player.currentTime(); // 获取当前播放时间
          // console.log(currentTime);
          if(currentTime > 9.7) {
            this.player.currentTime(4.49);
          }
        });

    },
    beforeDestroy() {
        if (this.player) {
            this.player.dispose()
        }
    }
}
</script>

Logo

一站式 AI 云服务平台

更多推荐