flymigo
flymigo
  • 发布:2021-06-27 15:17
  • 更新:2021-12-27 13:39
  • 阅读:889

【报Bug】微信小程序下华为手机live-pusher 的 snapshot 回调执行

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

第三方开发者工具版本号: 3.1.9 Hbuilder X

基础库版本号: 2.10.4

项目创建方式: CLI

CLI版本号: 2.0.0-26520200314001

操作步骤:

华为mete 30 真机点击识别

预期结果:

snapshot 回调成功

实际结果:

snapshot 回调无结果 无报错

bug描述:

live pusher 在andorid 真机下snapshot 函数无回调/不报错。 startPreview回调可执行。问题只有andorid 环境,ios系统无问题。
测试android机器型号 : 华为mate30
代码如下
<template>
<view class="">
<view class="custom" :style="{height: CustomBar+'px'}">
<view class="navcontent" :style="[{top:statusBar + 'px'}]">
<text class=" iconfont i-icon-return text-bold text-black text-xxl bg-white "
style="width: 60rpx;height: 60rpx;opacity: 0.9;left:-56rpx" @click.prevent.stop="BackPage"></text>

            <text class="text-black text-bold text-xl" style="line-height: 45px;">刷脸</text>  
            <text></text>  
        </view>  
    </view>  
    <view class="livefater">  
        <view style="width: 348px;height: 348px;border-radius: 348px;overflow: hidden;background-color: #CCCCCC;">  
            <live-pusher id='livePusher' ref="livePusher" class="livePusher" url="https://domain/push_stream"   
                waiting-image="https://www.standardtec.cn/wp-content/uploads/2020/09/cropped-logo-lg-60x60.png" mode="SD" :muted="true"  
                :enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2" aspect="1:1" min-bitrate="1000"  
                audio-quality="16KHz" :enable-mic="false" :zoom="false" @statechange="statechange"  
                @netstatus="netstatus" @error="error"></live-pusher>  
        </view>  
        <cover-image src="../../static/images/round.png" class="gaiimg"></cover-image>  
    </view>  
    <view class="padding  justify-center" style="display:flex;flex-direction: row;">  
        <view class="basis-xsg">  
            <button class="cu-btn  bg-grey " @click="BackPage"><text  
                    class="iconfont text-lg margin-right-xs i-icon-return"></text>返回</button>  
        </view>  
        <view class="margin-lr basis-xsg">  
            <button :class="loading ? 'bg-grey':'bg-blue'" class="cu-btn   " @click="snapshot"><text  
                    class="iconfont text-lg margin-right-xs i-icon-businesscard">  
                </text>识别</button>  
        </view>  
        <view class="basis-xsg">  
            <button class="cu-btn  bg-grey " @click="switchCamera"><text  
                    class="iconfont text-lg margin-right-xs i-icon-camera">  
                </text>切换</button>  
        </view>  

    </view>  
    <i-toast id="toast" />  
</view>  

</template>

<script>
const app = getApp();
const {
$Toast
} = require('../../wxcomponents/iview/base/index');
import {
get,
post,
put
} from '@/http/api'
import {
getters,
mapState
} from 'vuex'
export default {
data() {
return {
livePusher: null, //流视频对象
course: null,
fil: true,
imgList: [""],
statusBar: 0,
CustomBar: 0,
loading: false
}
},
computed: {
...mapState([
'sessionkey', 'userInfo', 'userid', 'orgId', 'userRole', 'chargeOrg'
]),
mapOtids() {
let that = this;
let result = {}
if (that.course == null || that.course.trainees.length == 0) return result;
that.course.trainees.forEach((item, index, array) => {
result[item.otId] = "1";
})
return result;
}
},
onLoad() {
let query = this.$route.query;
this.CustomBar = app.globalData.CustomBar;
this.course = JSON.parse(decodeURIComponent(query.course))
},
onUnload() {
let that = this;
that.stopPreview();
let orgId = that.orgId;
let trainees = encodeURIComponent(JSON.stringify(that.course.trainees));
let id = that.course._id;
that.$eventHub.$emit('trainees', {
trainees,
id
});
},
mounted() {

    },  
    onReady() {  
        this.livePusher = uni.createLivePusherContext('livePusher', this);  
        this.startPreview(); //开启预览并设置摄像头  
        var that = this  
        uni.getSystemInfo({  
            success: function(e) {  
                // 计算导航栏高度  
                that.statusBar = e.statusBarHeight  
                // #ifndef MP    
                if (e.platform == 'android') {  
                    that.CustomBar = e.statusBarHeight + 50  
                } else {  
                    that.CustomBar = e.statusBarHeight + 45  
                }  
                // console.log(that.statusBar)  
                // #endif    
                // #ifdef MP-WEIXIN    
                let custom = wx.getMenuButtonBoundingClientRect()  
                that.CustomBar = custom.bottom + custom.top - e.statusBarHeight  

                // #endif    

            }  
        })  
    },  
    methods: {  
        statechange(e) {  
            // console.log("statechange:" + JSON.stringify(e));  
        },  
        netstatus(e) {  
            // console.log("netstatus:" + JSON.stringify(e));  
        },  

        error(e) {  
            console.log("error:" + JSON.stringify(e));  
        },  
        switchCamera: function() {  
            this.livePusher.switchCamera({  
                success: (a) => {  
                    // console.log("switch camera:" + JSON.stringify(a));  
                }  
            })  
        },  
        start: function() {  
            this.livePusher.start({  
                success: (a) => {  
                    // console.log("livePusher.start:" + JSON.stringify(a));  
                }  
            });  
        },  
        close: function() {  
            this.livePusher.close({  
                success: (a) => {  
                    // console.log("livePusher.close:" + JSON.stringify(a));  
                }  
            });  
        },  
        // 拍照事件  
        snapshot: function() {  
            let that = this;  
            uni.getSetting({  
                success(res) {  
                    if(!res.authSetting['scope.writePhotosAlbum']){  
                        uni.authorize({  
                            scope:'scope.writePhotosAlbum',  
                            success() {  
                                that.takeSnapShot();  
                            },  
                            fail() {  
                                $Toast({  
                                    type: 'warning',  
                                    content: '请授权后再操作',  
                                    duration: 5  
                                });  
                            }  
                        })  
                    }else{  
                        that.takeSnapShot()  
                    }  
                }  
            })  
        },  
        takeSnapShot(){  
            let that = this;  
            if (that.loading == true) return;  
            let flag = that.checkCanQuery();  
            if (flag == false) {  
                return;  
            }  
            that.livePusher.snapshot({  
                success: (e) => {  
                    console.log("livePusher snapshot:" + JSON.stringify(e));  
                    that.getMinImage(e.tempImagePath)  
                }  
            });  
        },  
        // 开启摄像头  
        startPreview() {  
            var that = this  
            this.livePusher.startPreview({  
                success: (a) => {  
                    console.log("livePusher.startPreview:" + JSON.stringify(a));  
                }  
            });  
        },  
        stopPreview: function() {  
            this.livePusher.stopPreview({  
                success: (a) => {  
                    console.log("livePusher.stopPreview:" + JSON.stringify(a));  
                }  
            });  
        },  
        getMinImage(imgPath) {  
            let that = this;  
            uni.compressImage({  
                src: imgPath,  
                quality: 20,  
                success: res => {  
                    console.log(res)  
                    uni.getFileSystemManager().readFile({  
                        filePath: res.tempFilePath, //选择图片返回的相对路径  
                        encoding: 'base64', //编码格式  
                        success: res => { //成功的回调                                     
                            let base64 = res.data ;  
                            // console.log("base64 img:" + base64);  
                            console.log(base64)  
                            that.getTrainees(base64);  
                        },  
                        fail: (e) => {  
                            console.log("图片转换失败");  
                        }  
                    })  

                }  
            });  
        },  
        checkCanQuery() {  

        },  
                   getTrainees(strBase){  

                    },  
        BackPage() {  
            uni.navigateBack({  
                delta: 1  
            });  
        }  

    }  
}  

</script>

<style scoped>
.custom {
background-color: #FFFFFF;
}

.navcontent {  
    height: 45px;  
    display: -ms-flex;  
    display: -webkit-flex;  
    display: flex;  
    justify-content: space-around;  
    flex-direction: row;  
    color: #333333;  
}  

.livePusher {  
    width: 350px;  
    height: 350px;  
}  

.livefater {  
    display: -ms-flex;  
    display: -webkit-flex;  
    display: flex;  
    justify-content: center;  
    flex-direction: column;  
    align-items: center;  
    margin-top: 50rpx;  
    margin-bottom: 50rpx;  
    height: 350px;  
}  

.gaiimg {  
    width: 350px;  
    height: 350px;  
    margin-top: -350px;  
}  

</style>

2021-06-27 15:17 负责人:无 分享
已邀请:
周工子

周工子

遇到同样的问题 期待解决

h***@163.com

h***@163.com

同样问题 期待解决

该问题目前已经被锁定, 无法添加新回复