播放视频页面添加

This commit is contained in:
cjl520cy 2026-04-24 17:54:24 +08:00
parent f1e4ee07b0
commit 9de417bdfc
4 changed files with 129 additions and 8 deletions

View File

@ -10,6 +10,13 @@
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"screenOrientation" : [
//
"portrait-primary", //
"portrait-secondary", //
"landscape-primary", //
"landscape-secondary" //
],
"compatible" : {
"ignoreVersion" : true //trueHBuilderX1.9.0
},

View File

@ -596,6 +596,12 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/shop/photoAlbum/videoplayer",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/shop/photoAlbum/videoList",
"style": {

View File

@ -220,14 +220,16 @@
// uni.navigateTo({
// url: `/pages/album/list?urls=${encodeURIComponent(JSON.stringify(urls))}`
// });
this.videoPlay = true; //
this.videoContext = uni.createVideoContext("myvideo", this); // this
this.videoUrl = this.formData.url;
this.videoContext.requestFullScreen({
direction: 90
});
this.videoContext.play();
// this.videoPlay = true; //
// this.videoContext = uni.createVideoContext("myvideo", this); // this
// this.videoUrl = this.formData.url;
// this.videoContext.requestFullScreen({
// direction: 90
// });
// this.videoContext.play();
uni.navigateTo({
url: '/pages/shop/photoAlbum/videoplayer?url=' + this.formData.url
})
},
async submitPhoto() {

View File

@ -0,0 +1,106 @@
<template>
<view class="video-page">
<!-- 原生视频组件全端兼容 -->
<video id="fullVideo" class="video-box" :src="videoUrl" controls show-fullscreen-btn enable-progress-gesture
:autoplay="true" :loop="false" :muted="false" @play="onPlay" @pause="onPause" object-fit="cover" :direction="90"
@fullscreenchange="handleFullScreenChange" @ended="onVideoEnd" @fullscreenclick="tapback"></video>
</view>
</template>
<script>
export default {
data() {
return {
videoUrl: "",
videoContext: null
};
},
onLoad(options) {
console.log(options, '页面参数');
//
if (options.url) {
this.videoUrl = options.url;
}
},
onReady() {
// #ifdef APP-PLUS
//plus.screen.unlockOrientation(); //
// #endif
//
this.videoContext = uni.createVideoContext("fullVideo", this);
//
//this.autoFullScreen();
},
methods: {
tapback(e) {
console.log('点击全屏按钮');
// if (e.target.fullScreen) {
// plus.screen.lockOrientation('landscape'); //
// }else{
// plus.screen.lockOrientation('portrait'); //
// }
},
// iOS
autoFullScreen() {
if (!this.videoContext) return;
// iOS090
const direction = uni.getSystemInfoSync().platform === 'ios' ? 0 : 90;
//
setTimeout(() => {
this.videoContext.requestFullScreen({
direction: direction
});
}, 300)
},
//
openFullScreen() {
if (!this.videoContext) return;
const direction = uni.getSystemInfoSync().platform === 'ios' ? 0 : 90;
this.videoContext.requestFullScreen({
direction
});
},
// 退
closeFullScreen() {
if (!this.videoContext) return;
this.videoContext.exitFullScreen();
},
//
onPlay() {
console.log("视频开始播放");
},
//
onPause() {
console.log("视频暂停");
},
//
handleFullScreenChange(e) {
// 退
// uni.setNavigationBarHidden(!!e.detail.fullScreen);
console.log("全屏状态:", e.detail.fullScreen);
},
//
onVideoEnd() {
this.closeFullScreen();
}
}
};
</script>
<style scoped>
.video-page {
width: 100%;
height: 100vh;
box-sizing: border-box;
}
.video-box {
width: 100%;
/* 自适应高度,避免拉伸 */
height: 100%;
object-fit: cover;
}
</style>