mrr.sj.front/pages/album/components/videoSlide.nvue

88 lines
2.0 KiB
Plaintext
Raw Normal View History

2026-03-24 11:45:13 +08:00
<template>
2026-06-01 13:54:04 +08:00
<view class="video-page">
<!-- 原生视频组件:全端兼容 -->
<video id="fullVideo" class="video-box" :src="videoUrl" controls show-fullscreen-btn enable-progress-gesture
:autoplay="false" :loop="false" :muted="false" @play="onPlay" @pause="onPause"
@fullscreenchange="handleFullScreenChange" @ended="onVideoEnd"></video>
<!-- 自定义操作按钮 -->
<view class="btn-wrap">
<button type="primary" size="default" @click="openFullScreen">
手动横屏全屏播放
</button>
<button type="warn" size="default" @click="closeFullScreen">
退出全屏
</button>
2026-03-24 11:45:13 +08:00
</view>
</view>
</template>
<script>
export default {
data() {
return {
2026-06-01 13:54:04 +08:00
// 测试视频地址,替换自己的
videoUrl: "https://www.w3school.com.cn/i/movie.mp4",
videoContext: null
2026-03-24 11:45:13 +08:00
};
},
2026-06-01 13:54:04 +08:00
onReady() {
// 初始化视频实例
this.videoContext = uni.createVideoContext("fullVideo", this);
2026-03-24 11:45:13 +08:00
},
methods: {
2026-06-01 13:54:04 +08:00
// 进入横屏全屏
openFullScreen() {
// direction 90横屏-90反向横屏0自适应
this.videoContext.requestFullScreen({
direction: 90
});
},
// 退出全屏
closeFullScreen() {
this.videoContext.exitFullScreen();
},
// 播放监听
onPlay() {
console.log("视频开始播放");
},
// 暂停监听
onPause() {
console.log("视频暂停");
},
// 全屏状态切换监听
handleFullScreenChange(e) {
if (e.detail.fullScreen) {
uni.setNavigationBarHidden(true); // 全屏隐藏顶部导航
2026-03-24 11:45:13 +08:00
} else {
2026-06-01 13:54:04 +08:00
uni.setNavigationBarHidden(false); // 退出恢复导航
2026-03-24 11:45:13 +08:00
}
2026-06-01 13:54:04 +08:00
console.log("当前全屏状态:", e.detail.fullScreen);
2026-03-24 11:45:13 +08:00
},
2026-06-01 13:54:04 +08:00
// 视频播放结束
onVideoEnd() {
// 播放完毕自动退出全屏
this.videoContext.exitFullScreen();
2026-03-24 11:45:13 +08:00
}
}
2026-06-01 13:54:04 +08:00
};
2026-03-24 11:45:13 +08:00
</script>
2026-06-01 13:54:04 +08:00
<style scoped>
.video-page {
padding: 15rpx;
2026-03-24 11:45:13 +08:00
}
.video-box {
2026-06-01 13:54:04 +08:00
width: 100%;
height: 420rpx;
border-radius: 12rpx;
overflow: hidden;
2026-03-24 11:45:13 +08:00
}
2026-06-01 13:54:04 +08:00
.btn-wrap {
margin-top: 30rpx;
2026-03-24 11:45:13 +08:00
display: flex;
2026-06-01 13:54:04 +08:00
gap: 20rpx;
2026-03-24 11:45:13 +08:00
}
</style>