88 lines
1.9 KiB
Vue
88 lines
1.9 KiB
Vue
<template>
|
|
<view class="">
|
|
<video
|
|
class="video"
|
|
:show-fullscreen-btn="false"
|
|
:direction="videoDirection"
|
|
id="myVideo"
|
|
autoplay
|
|
:src="curPlayVideoUrl"
|
|
@loadedmetadata="handleLoadedMetadata"
|
|
@error="videoErrorCallback"
|
|
controls
|
|
></video>
|
|
</view>
|
|
</template>
|
|
<script>
|
|
import uniPopup from '@/components/uni-popup/uni-popup.vue'
|
|
import { pageListenMixins } from '@/mixins/pageListenMixins'
|
|
export default {
|
|
components:{
|
|
uniPopup
|
|
},
|
|
mixins: [pageListenMixins],
|
|
data() {
|
|
return {
|
|
curPlayVideoUrl:'',
|
|
isVideoPopupShow:false,
|
|
pageKeyId: '',
|
|
videoDirection: 90,
|
|
hasLoadedMetadata: false,
|
|
hasRequestedFullscreen: false
|
|
}
|
|
},
|
|
onReady(res) {
|
|
this.videoContext = uni.createVideoContext('myVideo');
|
|
},
|
|
onLoad(options) {
|
|
if (!options.click) {
|
|
uni.switchTab({ url: '/pages/home/index' })
|
|
return
|
|
}
|
|
this.curPlayVideoUrl = options.videoUrl
|
|
const id = options.id
|
|
this.pageKeyId = `findVideo_videoId_${id}`
|
|
},
|
|
methods: {
|
|
handleLoadedMetadata(e) {
|
|
const detail = e.detail || {}
|
|
const width = Number(detail.width) || 0
|
|
const height = Number(detail.height) || 0
|
|
|
|
if (height > width && width > 0) {
|
|
this.videoDirection = 0
|
|
} else {
|
|
this.videoDirection = 90
|
|
}
|
|
|
|
this.hasLoadedMetadata = true
|
|
this.enterFullScreen()
|
|
},
|
|
enterFullScreen() {
|
|
if (!this.videoContext || !this.hasLoadedMetadata || this.hasRequestedFullscreen) {
|
|
return
|
|
}
|
|
this.hasRequestedFullscreen = true
|
|
this.videoContext.requestFullScreen({
|
|
direction: this.videoDirection
|
|
})
|
|
},
|
|
videoErrorCallback: function(e) {
|
|
uni.showModal({
|
|
content: e.target.errMsg,
|
|
showCancel: false
|
|
})
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
.video{
|
|
height: 100vh;
|
|
width: 100vw;
|
|
}
|
|
|
|
</style>
|