<template>
	<view>
		<video class="video" :src="item.mediaurl" controls object-fit="cover"
			id="videoPlayer" :poster="item.coverurl" @play="doPlay($event)"
			:initial-time="current" style="width: 100%;" @timeupdate="timeupdate($event)"
			@pause="doPlay($event)" @ended="doPlay($event)">
		</video>
	</view>
</template>

<script>
export default {
		data() {
			return {
				item: {},
				videoId:0,
				current:0,
				currentTime:0,
				alreadyPlay:false,
			}
		},
		onLoad(options) {
			// debugger;
			this.videoId = options.id;
			if(options.current){
				this.current = options.current;
			}else{
				this.$u.api.getVideoRecord(options.id).then(res => {
					this.current = res.data.current;
				})	
			}
			this.$u.api.getThisVideo(options.id).then(res => {
				this.item = res.data;
				// console.log(res.data)
			})
		},
		methods:{
			doPlay(e) {
				if(this.alreadyPlay){}else{
					debugger;
					this.alreadyPlay =true;
					this.$u.api.putMyVideoView(this.videoId).then(res=>{})
				}
				// videoContextPrev.pause();
			},
			timeupdate(e){
				let currentTime = Math.floor(e.detail.currentTime);
				this.currentTime =currentTime;
			},
		},
		beforeDestroy(){
			debugger;
			let params = {'current':this.currentTime};
			this.$u.api.putMyVideoView(this.item.id,params).then(res => {
			})
		},
	}
</script>

<style>
</style>
