关于uni-app中Android不支持camera相机组件进行拍照,并需要改变调用uni.chooseImage时手机相机UI的替代解决方法
uni-app中Android不支持camera相机组件
uni-app中Android与H5不支持camera相机组件,但是你可以调用uni.chooseImage进行拍照(不足:不可以自己来修改相机页面的UI,因为它是调用手机的相机)
解决办法live-pusher组件进行替代
live-pusher组件是uni-app实时音视频录制,也称直播推流的组件。(注意:用live-pusher组件时要使用nvue 页面,不要使用vue 页面,要不然会无效)
使用live-pusher的uni.createLivePusherContext的snapshot方法可以来实现拍照功能,而且可以自己来写相机的UI。
下面展示一些 我运用live-pusher组件的代码,其中删除了一些其他无关的代码
。
<template>
<live-pusher id='livePusher' ref="livePusher" class="livePusher" url=""
mode="SD" :muted="true" :enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2"
aspect="9:16" @statechange="statechange" @netstatus="netstatus" @error = "error"
></live-pusher>
</template>
<script>
export default {
data() {
return {
};
},
onLoad(options) {
},
onReady(){
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
//开始直播推流,也即打开摄像头
this.context.startPreview({
success: (a) => {
console.log("livePusher.startPreview:" + JSON.stringify(a));
}
});
},
methods: {
//照相
takePhoto(){
//进行照相
this.context.snapshot({
success: (e) => {
console.log(JSON.stringify(e));
}
});
}
},
}
</script>