index.vue 2.6 KB
<template>
	<view class="content">

		<video id='video' class="video" :poster="poster" :src="url" direction="-90" show-mute-btn
			@timeupdate="timeupdate" @play="onstart" @pause="onpause" @ended="onfinish" @error="onfail"></video>
		<image v-if="showPic" :src="poster" style="width: 750rpx;height: 400rpx;position: absolute;left: 0;top: 0;"
			mode="aspectFill"></image>
		<!-- @play="onstart" -->
		<!-- @pause="onpause" @ended="onfinish" @error="onfail" @waiting="waiting" @timeupdate="timeupdate" -->
		<!-- @fullscreenchange="fullscreenchange" -->
	</view>
</template>

<script>
	import throttle from '@/utils/throttle.js'
	export default {
		data() {
			return {
				url: '',
				poster: '',
				lessons_id: '',
				token: '',
				context: null,
				api: '',
				showPic: true
			}
		},
		onReady() {
			this.context = uni.createVideoContext("video", this);
		},
		onLoad(e) {
			console.log(123, e)
			this.poster = e.poster
			this.url = e.url
			this.token = e.token
			this.lessons_id = e.lessons_id
			this.api = e.api
			if (e.seek) {
				this.$nextTick(() => {
					this.seek(e.seek);
					this.play();
				})
			}
		},
		methods: {
			onstart(e) {
				this.showPic = false
				// console.log("onstart:" + JSON.stringify(e));
			},
			onpause(e) {
				// console.log("onpause:" + JSON.stringify(e));
			},
			onfinish(e) {
				// console.log("onfinish:" + JSON.stringify(e));
			},
			onfail(e) {
				// console.log("onfail:" + JSON.stringify(e));
			},
			fullscreenchange(e) {
				// console.log("fullscreenchange:" + JSON.stringify(e));
			},
			waiting(e) {
				// console.log("waiting:" + JSON.stringify(e));
			},
			timeupdate(e) {
				this.showPic = false
				throttle(() => {
					uni.request({
						url: this.api + 'api/course.learning/syncUserLearningRecord',
						header: {
							token: this.token,
						},
						data: {
							lessons_id: this.lessons_id
						},
						complete(res) {
							console.log("timeupdate:" + JSON.stringify(res));
						}
					})
				}, 60000, false)
			},

			play() {
				this.context.play();
			},
			// pause() {
			// 	this.context.pause();
			// },
			seek(time) {
				this.context.seek(time);
			},
			// stop() {
			// 	this.context.stop();
			// },
			// fullScreen() {
			// 	this.context.requestFullScreen({
			// 		direction: 90
			// 	});
			// },
			// exitFullScreen() {
			// 	this.context.exitFullScreen();
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 750rpx;
		height: 400rpx;
		overflow: hidden;
		position: relative;
	}

	.video {
		width: 750rpx;
		height: 400rpx;
	}
</style>