app利用live-pusher直播推流时,进入页面默认横屏

<live-pusher orientation="horizontal" id="livePusher" ref="livePusher" style="width: 100%;height: 100%;"
			class="livePusher" url="rtmp://....." mode="FHD" :muted="false"
			:enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2" @statechange="statechange"
			@netstatus="netstatus" @error="error"></live-pusher>

业务需求为,当点击开始直播时,默认进入直播页面,并横屏显示

从live-pusher的官方api中,并没有看到可以直接控制界面横屏显示像,但是存在orientation项,这个是可以进行利用的

其中的调研也实验了许多,也不是很好用,当时想到了可以使用重力感应,动态改变orientation的值

plus.screen.unlockOrientation('portrait-primary');
			/* 5+环境屏幕旋转 */
			watchScheen = setInterval(()=>{
				// 屏幕方向数值: HOME键在右, 0 - 竖屏; 90 - 横屏;  HOME'键在左, 180 - 反向竖屏; -90 - 反向横屏;
				let c = plus.navigator.getOrientation();
				if(c == 0){
					console.log('竖屏',c)
					plus.screen.lockOrientation('portrait-primary'); //锁定竖屏
					plus.navigator.setStatusBarStyle('dark');
					plus.screen.unlockOrientation();
					uni.showTabBar()
				} else if(c == 180){
					console.log('反向竖屏',c)
					plus.screen.lockOrientation('portrait-secondary'); //锁定横屏
					plus.navigator.setStatusBarStyle('dark');
					plus.screen.unlockOrientation();
					uni.hideTabBar()
				} else if(c == -90){
					console.log('反向横屏',c)
					plus.screen.lockOrientation('landscape-secondary'); //锁定反向横屏
					plus.navigator.setStatusBarStyle('dark');
					plus.screen.unlockOrientation();
					uni.hideTabBar()
				} else {
					console.log('横屏',c)
					plus.screen.lockOrientation('landscape-primary'); //锁定反向横屏
					plus.navigator.setStatusBarStyle('dark');
					plus.screen.unlockOrientation();
					uni.hideTabBar()
				}
			},200)
                        
原文链接:https://blog.csdn.net/weixin_50466102/article/details/132035425

也是参考了大佬的文章,但是发现跟我的业务需求并不完全符合,因为需要结合orientation属性,因为只有“锁定反向横屏”的时候,页面才是我想要的结果。

所以,想着直接进入页面时,可不可以做一些操作,可以直接锁定到我想要的屏幕效果,经过下方代码,就可以实现该需求

vue2

onLoad() {
			// #ifdef APP-PLUS
			setTimeout(() => {
				plus.screen.unlockOrientation();
				plus.screen.lockOrientation('landscape-primary');
 
			}, 600)
			// #endif
		},
		onUnload() {
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary');
			// #endif
		},

                        
原文链接:https://blog.csdn.net/weixin_68658847/article/details/140294602

vue3

<script setup>
	import {
		onMounted
	} from 'vue';

	onMounted(() => {
		setTimeout(() => {
			plus.screen.unlockOrientation();
			plus.screen.lockOrientation('landscape-primary');

		}, 600)
	});
</script>

                        
原文链接:https://blog.csdn.net/weixin_68658847/article/details/140294602
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值