j-video.vue 2.1 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<template>
<view class="root" :style="{width,height}">
	<image :style="{width,height}" class="posterImg" :src="posterUrl" mode="aspectFit"></image>
	<view :style="{width,height}" @click="play" class="box">
		<image class="playIcon" src="../../static/play.png" mode="widthFix"></image>
	</view>
	<video
		id="myVideo"
		style="width: 1px;height: 1px;"
		:src="src"
		@timeupdate="timeupdate"
		@fullscreenchange="fullscreenchange"
	></video>
</view>
</template>

<script>
var videoContext;
	export default {
		mounted() {
			videoContext = uni.createVideoContext('myVideo',this)
		},
		computed:{
			posterUrl(){
				if(this.poster) return this.poster
				return this.src + '?x-oss-process=video/snapshot,t_'+(parseInt(this.currentTime*1000))+',f_jpg,w_800,m_fast'
			}
		},
		methods:{
			fullscreenchange(e){
				console.log(e.detail.fullScreen);
				this.state = e.detail.fullScreen
				if(!e.detail.fullScreen){
					videoContext.pause()
				}
			},
			timeupdate(e){
A
Anne_LXM 已提交
38
				// console.log(e.detail);
study夏羽's avatar
study夏羽 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
				this.duration = e.detail.duration
				this.currentTime = e.detail.currentTime
			},
			play(){
				videoContext.play()
				videoContext.requestFullScreen({direction:this.direction})
			}
		},
		watch: {
		},
		data() {
			return {
				state:false,
				currentTime:0,
				duration:0,
				videoId:''
			};
		},
		props: {
			poster: {
				type: [String,Boolean],
				default(){
A
Anne_LXM 已提交
61
					return 'https://web-assets.dcloud.net.cn/unidoc/zh/schema2code-poster.jpg'
study夏羽's avatar
study夏羽 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
				}
			},
			src: {
				type: String,
				default(){
					return ''
				}
			},
			title: {
				type: String,
				default(){
					return ''
				}
			},
			direction: {
				type: Number,
				default(){
					return -90
				}
			},
			width: {
				type: String,
				default(){
					return "750rpx";
				}
			},
			height: {
				type: String,
				default(){
					return "450rpx";
				}
			}
		},
	}
</script>

<style scoped>
.root{
	position:relative;
	width: 750rpx;
	height: 300px;
	overflow: hidden;
}
.posterImg,.video,.box{
	display: flex;
	width: 750rpx;
	height: 300px;
	position:absolute;
}
.posterImg{
}
.box{
	justify-content: center;
	align-items: center;
}
.playIcon{
	width: 100rpx;
}
</style>