前端监听视频播放进度,在试看结束后做一些操作

HTML

<video :src="class_info.video_audio_url"
	id="myVideo"
	:poster="imgurl"       
	@timeupdate="videoTimeUpdateEvent">
</video>

JavaScript

data() {
	return {
		videoContext: {},  // 用于绑定视频标签
	}
},
created() {
	// 创建视频实例指向视频控件
	this.videoContext = uni.createVideoContext('myVideo');
},
videoTimeUpdateEvent(e) { // 播放进度改变
	// e.detail.currentTime为每次触发时,视频的当前播放时间
	let currentTime = Number(e.detail.currentTime);
	console.log('播放进度条改变', currentTime)
	// 试看结束 this.class_info.freed_time为试看时间
	if (currentTime >= this.class_info.freed_time) {
		// 试看结束,在这做一些想做的操作,例如停止视频播放
		this.videoContext.exitFullScreen();
		this.videoContext.pause();
		this.videoContext.seek(0);
	}
},

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐