wx.createVideoContext 全屏播放

本文探讨了在微信小程序中实现视频全屏播放的方法。通过为不同页面的video组件分配唯一的ID,确保了多个视频播放功能在同一应用中互不干扰。文章详细介绍了如何使用wx.createVideoContext创建视频上下文,并调用requestFullScreen和play方法来实现全屏播放。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们小程序里面 有两个页面 会需要进入 video 的全屏播放
new-moment 我定义 video 的id 是 playVideo
然后 点击播放的时候 触发一个方法 内容写成

this.videoContext = wx.createVideoContext('myNewVideo')
this.videoContext.requestFullScreen()
this.videoContext.play()

这样就 可以进入全屏播放

但是
我再另一个页面 moment-detail 中也有一个 video 播放的功能, 这时候 如果你的 video id属性 不能和 其他页面的 video 名字重合 如果重合就不能进入全屏播放了。

<view class="video" v-if="item && item.video_url"> <Player style="width: 100%;" :key="index" :index="index" :video-url="item.video_url" :cover-url="item.cover_url" @play="handleVideoPlay" /> </view> handleVideoPlay(index) { if(this.currentIndex !== null && this.currentIndex !== index) { const prevVideo = uni.createVideoContext('video'+this.currentIndex, this) prevVideo.pause() prevVideo.exitFullScreen() } this.currentIndex = index }, <template> <view class="video-box"> <video style="width: 100%;" :id="'video'+index" :src="videoUrl" :poster="coverUrl" :controls="true" :show-fullscreen-btn="true" :show-center-play-btn="true" :enable-progress-gesture="true" @fullscreenchange="handleFullscreen" @play="onPlay" @pause="onPause" @click="toggleFullscreen" ></video> </view> </template> <script> export default { props: { videoUrl: String, coverUrl: String, index: Number }, methods: { toggleFullscreen() { // const videoCtx = uni.createVideoContext('video'+this.index, this) // if(this.isFullscreen) { // videoCtx.pause() // videoCtx.exitFullScreen() // } else { // // 关键修改:移除方向参数 // videoCtx.requestFullScreen() // } const videoCtx = uni.createVideoContext('video'+this.index, this) // #ifdef APP-PLUS plus.screen.lockOrientation('portrait-primary') // 临时允许横屏 // #endif videoCtx.requestFullScreen() }, handleFullscreen(e) { this.isFullscreen = e.detail.fullScreen // #ifdef APP-PLUS if(!e.detail.fullScreen) { plus.screen.lockOrientation('portrait-primary') } // #endif // #ifdef APP-PLUS && IOS plus.screen.unlockOrientation() plus.navigator.setStatusBarStyle('dark') // #endif }, onPlay() { this.$emit('play', this.index) }, onPause() { this.$emit('pause', this.index) } }, data() { return { isFullscreen: false } } } </script> <style> .video-box{ width: 100%; height: 100vh; /* 强制占满屏幕高度 */ } </style> uniapp 安卓点击视频播放全屏按钮后 也是横屏的 怎么在代码里禁止
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值