shop_uniapp/components/j-video/j-video.vue

116 lines
2.2 KiB
Vue
Raw Permalink Normal View History

2024-06-06 09:55:01 +08:00
<template>
<view class="root" :style="{width,height}">
<image :style="{width,height}" class="posterImg" :src="posterUrl"></image>
<view :style="{width,height}" @click="state=!state" class="box">
2024-11-15 16:09:39 +08:00
<image class="playIcon" :src="aliOSS + 'uniapp/icon_play.png'" mode="widthFix"></image>
2024-06-06 09:55:01 +08:00
</view>
<video :id="videoId" :style="{height,width:state?'750rpx':'1rpx'}" @pause="state=0" @timeupdate="timeupdate" @fullscreenchange="fullscreenchange" class="video" :src="url"></video>
</view>
</template>
<script>
export default {
computed:{
posterUrl(){
if(this.poster) return this.poster
return this.url + '?x-oss-process=video/snapshot,t_'+(parseInt(this.currentTime*1000))+',f_jpg,w_800,m_fast'
}
},
created() {
this.videoId = Date.now() + Math.ceil(Math.random()*10000000)+"";
},
mounted() {
this.VideoContext = uni.createVideoContext(this.videoId, this)
},
methods:{
fullscreenchange(e){
this.state = e.detail.fullScreen
},
timeupdate(e){
this.duration = e.detail.duration
this.currentTime = e.detail.currentTime
}
},
watch: {
state(state, oldValue) {
if(!state){
this.VideoContext.pause()
}else{
this.VideoContext.play()
setTimeout(()=>{
this.VideoContext.requestFullScreen({direction:this.direction})
},10)
}
}
},
data() {
return {
VideoContext:{},
state:false,
currentTime:0,
duration:0,
videoId:''
};
},
props: {
poster: {
type: [String,Boolean],
default(){
return ''
}
},
url: {
type: String,
default(){
return ''
}
},
direction: {
type: Number,
default(){
return 0
}
},
width: {
type: String,
default(){
return "750rpx";
}
},
height: {
type: String,
default(){
return "450rpx";
}
}
},
}
</script>
<style lang="scss" scoped>
.root{
position:relative;
width: 750rpx;
height: 300px;
overflow: hidden;
}
.posterImg,.video,.box{
display: flex;
width: 750rpx;
height: 300px;
position:absolute;
}
.video{
margin-left: -2000px;
}
2024-06-20 02:45:12 +08:00
2024-06-06 09:55:01 +08:00
.box{
justify-content: center;
align-items: center;
}
.playIcon{
width: 100rpx;
height: 100rpx;
}
</style>