uni-app live-pusher设置默认后置相机 安卓有效 ios无效
uni-app live-pusher设置默认后置相机 安卓有效 ios无效
测试过的手机
华为p30默认【后置】是正确的,iphone12promax默认前置镜头
示例代码:
<live-pusher
id="livePusher"
ref="livePusher"
class="livePusher"
mode="FHD"
beauty="0"
device-position="back"
whiteness="0"
:aspect="aspect"
min-bitrate="1000"
audio-quality="16KHz"
:auto-focus="true"
:muted="true"
:enable-camera="true"
:enable-mic="false"
:zoom="false"
@statechange="statechange"
:style="{ width: cameraWidth, height: cameraHeight }"
>
</live-pusher>
操作步骤:
- 在
live-pusher标签配置device-position="back"
预期结果:
- 预期安卓和ios默认都是后置镜头
实际结果:
- 安卓后置镜头,ios前置镜头
bug描述:
- 配置
device-position="back"在安卓生效,ios失效
更多关于uni-app live-pusher设置默认后置相机 安卓有效 ios无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
7 回复
我也遇到了同样的问题,怎么解决的
更多关于uni-app live-pusher设置默认后置相机 安卓有效 ios无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
我也遇到相同问题,大佬,你的解决了吗
没解决
回复 信赖的阿涛: 用vue页面写 无法抓拍 抓拍多次就会导致app闪退 你们都是咋解决的
回复 9***@qq.com: 那个页面我用的nvue
安卓一直没有前置相机
这是一个已知的iOS平台差异问题。device-position属性在iOS上确实存在限制,其初始值可能不生效。
解决方案:
- 通过API动态设置:在
mounted或页面显示时,使用createLivePusherContext()获取推流上下文,然后调用switchCamera()方法:
// 在页面显示时或mounted中
setTimeout(() => {
const livePusherContext = uni.createLivePusherContext('livePusher')
livePusherContext.switchCamera() // 切换到后置
}, 500) // 需要适当延迟确保组件已初始化
- 添加平台判断:
// 在methods中
initCamera() {
if (uni.getSystemInfoSync().platform === 'ios') {
setTimeout(() => {
const ctx = uni.createLivePusherContext('livePusher')
ctx.switchCamera()
}, 500)
}
}
- 监听状态变化后切换:
statechange(e) {
if (e.detail.code === 1004 && uni.getSystemInfoSync().platform === 'ios') {
// 摄像头启动成功后切换
const ctx = uni.createLivePusherContext('livePusher')
ctx.switchCamera()
}
}

