![哇塞呀](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/001/65/42/95_avatar_mid.jpg?v=1638608237)
- 发布:2022-03-18 14:33
- 更新:2024-08-26 22:16
- 阅读:1677
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows10
HBuilderX类型: Alpha
HBuilderX版本号: 3.4.1
手机系统: 全部
页面类型: nvue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
操作步骤:
live-pusher安卓黑屏 IOS白屏
live-pusher安卓黑屏 IOS白屏
预期结果:
live-pusher安卓黑屏 IOS白屏
live-pusher安卓黑屏 IOS白屏
实际结果:
live-pusher安卓黑屏 IOS白屏
live-pusher安卓黑屏 IOS白屏
bug描述:
<view>
<live-pusher id='livePusher' ref="livePusher" :style="{ width: windowWidth, height: windowHeight }" url=""
mode="SD" :muted="true" :enable-camera="true" :auto-focus="true"
@statechange="statechange" @netstatus="netstatus" @error="error" ></live-pusher>
<!-- <cover-image src="/static/cover_img.png" :style="{ width: windowWidth, height: imgHeight }" class="gaiimg"> -->
</cover-image>
</view>
</template>
<script>
// import {Filecreateperson} from '@/api/index.js'
export default {
data: {
fil: true,
imgList: [""],
issuccess: false,
Timer: null,
//屏幕可用宽度
windowWidth: '',
//屏幕可用高度
windowHeight: '',
//图片可用高度
imgHeight: '',
},
onLoad() {
this.initCamera();
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
setTimeout(() => {
this.startPreview()
}, 2000)
},
onUnload() {
this.Timer && clearInterval(this.Timer);
this.stopPreview();
},
methods: {
//获取屏幕高度
initCamera() {
let that = this
uni.getSystemInfo({
success: function(res) {
that.windowWidth = res.windowWidth;
that.windowHeight = res.windowHeight;
that.imgHeight=that.windowWidth*1624/750;
console.log(that.imgHeight);
}
});
},
// 开启摄像头
startPreview() {
console.log("livePusher.startPreview开始")
var that = this
this.context.startPreview({
success: (a) => {
console.log("livePusher.startPreview成功");
that.Timer = setInterval(function() {
that.snapshot()
if (that.issuccess) {
clearInterval(that.Timer)
}
}, 2000)
},
fail: (a) => {
console.log("livePusher.startPreview失败");
console.error(a);
}
});
},
//关闭摄像头
stopPreview() {
var that = this
this.context.stopPreview({
success: (a) => {
console.log("livePusher.stopPrevieww");
this.context = null;
},
complete: (a) => {
console.log(a);
}
});
},
statechange(e) {
console.log("statechange:" + JSON.stringify(e));
},
netstatus(e) {
console.log("netstatus:" + JSON.stringify(e));
},
error(e) {
console.log("error:" + JSON.stringify(e));
},
// 拍照事件
snapshot: function() {
var that = this
this.context.snapshot({
success: (e) => {
console.log(JSON.stringify(e));
that.getMinImage(e.message.tempImagePath)
}
});
},
// 使用plus.zip.compressImage压缩图片并转换成base64
getMinImage(imgPath) {
let that = this
plus.zip.compressImage({
src: imgPath,
dst: imgPath,
overwrite: true,
quality: 40
},
zipRes => {
setTimeout(() => {
// console.log(zipRes.target, 'file')
// this.submitPic(zipRes.target)
var reader = new plus.io.FileReader();
reader.onloadend = res => {
var speech = res.target.result; //人脸 base64图片
// console.log(speech,'speechspeech');
this.imgList.push(speech);
};
reader.readAsDataURL(plus.io.convertLocalFileSystemURL(zipRes.target));
}, 1000);
},
function(error) {
console.log('Compress error!', error);
}
);
},
//人脸采集
submitPic(fileData) {
// console.log(fileData, '人脸采集参数')
// Filecreateperson(fileData).then(res=>{
// if(res.code==200){
// this.issuccess=true;
// uni.navigateBack({
// delta:1
// })
// }
// console.log(res,'人脸采集结果');
// }).catch(res=>{
// console.log(res,'人脸采集结果失败');
// })
},
BackPage() {
uni.navigateBack({
delta: 1
});
}
}
}
</script>
<style>
.gaiimg {
position: absolute;
z-index: 100;
}
</style>
2***@qq.com
请问解决了吗
2022-10-07 17:56