在项目开发过程中,难免会用到video视频标签。根据客户要求,视频只能正常观看完,不能手动快进,以下是实现的方法:
<video id="myVideo" @timeupdate="videoFun" :src="videourl" initial-time="initial_time" >
<script>
export default {
data() {
return {
videourl: "https://vd3.bdstatic.com/mda-me38qw5ayq6m5x6k/sc/cae_h264/1620080580731464743/mda-me38qw5ayq6m5x6k.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1654941744-0-0-e46a5e5c83b069fcaf54124cd256af20&bcevod_channel=searchbox_feed&pd=1&cd=0&pt=3&logid=1944747745&vid=1074518001243819841&abtest=102599_2-102777_6-102784_1-17451_1-3000225_3-3000232_1&klogid=1944747745",
video_real_time: 0,
nitial_time: '',
}
},
onLoad(option) {
this.initial_time = '0'
},
methods: {
videoFun(e){
var isReady = 1;
let that = this;
var duration = e.detail.duration
var currentTime = parseInt(e.detail.currentTime)
if (that.video_real_time == 0) {
var jump_time = parseInt(that.initial_time) + parseInt(that.video_real_time)
} else {
var jump_time = parseInt(that.video_real_time)
}
if (isReady == 1) {
if (currentTime > jump_time && currentTime - jump_time > 3) {
let videoContext = wx.createVideoContext('myVideo')
videoContext.seek(that.video_real_time)
wx.showToast({
title: '未完整看完该视频,不能快进',
icon: 'none',
duration: 2000,
})
}
}
that.video_real_time = currentTime
}
}
}
</script>
|