1***@qq.com
1***@qq.com
  • 发布:2019-05-13 17:11
  • 更新:2020-10-27 14:49
  • 阅读:2815

【报Bug】调用录音时,app闪退了

分类:uni-app

今天在华为nova 4e 型号MAR-AL00 安卓9版本测试, 调用录音api时,app闪退了,但是在小米手机测试,不会出现,使用的老模板模式编译模式,代码如下:

<template>  
    <view class="record-index border-box" style="margin-bottom: 20upx;">  
        <view class="flex" style="justify-content: space-between;">  
            <view style="font-size:28upx;color:rgba(78,102,88,1);font-weight: bold;">语音描述(<text style="font-size: 24upx;color: #999999">录音时长最大为10分钟</text>)</view>  
            <view class="" style="font-size:28upx;color:rgba(204,113,102,1);font-weight:bold;" @tap="onDeleteTap" v-if="isRecord>=2">删除录音</view>  
        </view>  
        <view class="flex" style="align-items: center;justify-content: space-between;margin-top: 28upx;">  
            <view class="" style="width: 100%;">  
                <button v-if="isRecord < 2" @longpress="onStartRecordTap" @touchend="onStopRecordTap" type="primary" style="background: #66CC99;height: 72upx;line-height: 72upx;border-radius: 0;width: 100%;font-size: 28upx;">  
                    {{  
                        isRecord === 0?'点击录制':'录制中'  
                    }}  
                </button>  
                <button v-else @tap="onPlayRecordTap" type="primary" style="background: #66CC99;height: 72upx;line-height: 72upx;border-radius: 0;width: 100%;font-size: 28upx;">  
                    {{  
                        timing+(isRecord == 2?'   点击播放':'   正在播放')  
                    }}  
                </button>  
            </view>  

            <!-- <view  
                class="flex"  
                style="align-items: center;justify-content: space-between;width:464upx;background:rgba(255,255,255,1);box-shadow:0px 4px 8px rgba(0,0,0,0.08);height:72upx;border-radius:36upx;"  
            >  
                <view style="position: relative;width:310upx;height: 72upx;">  
                    <text style="width:310upx;height: 2upx;background: #66CC99;display: inline-block;position: absolute;top: 50%;transform: translateY(-50%);"></text>  
                    <view class="" v-if="isRecord ===3||isRecord ===1">  
                        <text class="billow billow1"  style="left: 20upx;"></text>  
                        <text class="billow billow2"  style="left: 35upx;"></text>  
                        <text class="billow billow3"  style="left: 50upx;"></text>  
                        <text class="billow billow4"  style="left: 65upx;"></text>  
                        <text class="billow billow5"  style="left: 80upx;"></text>  
                        <text class="billow billow6"  style="left: 95upx;"></text>  
                        <text class="billow billow1"  style="left: 110upx;"></text>  
                        <text class="billow billow2"  style="left: 125upx;"></text>  
                        <text class="billow billow3"  style="left: 140upx;"></text>  
                        <text class="billow billow4"  style="left: 155upx;"></text>  
                        <text class="billow billow5"  style="left: 170upx;"></text>  
                        <text class="billow billow6"  style="left: 185upx;"></text>  
                        <text class="billow billow1"  style="left: 200upx;"></text>  
                        <text class="billow billow2"  style="left: 215upx;"></text>  
                        <text class="billow billow3"  style="left: 230upx;"></text>  
                        <text class="billow billow4"  style="left: 245upx;"></text>  
                        <text class="billow billow5"  style="left: 260upx;"></text>  
                        <text class="billow billow6"  style="left: 275upx;"></text>  
                        <text class="billow billow1"  style="left: 290upx;"></text>  
                    </view>  
                </view>  
                <text class="border-box" style="font-size:28upx;color:rgba(102,204,153,1);padding: 0 16upx;">  
                    {{ timing }}  
                </text>  
            </view>  
            <view class="flex" style="align-items: center;">  
                <view class="" style="height: 72upx;line-height: 72upx;margin-right: 8upx;">  
                    <text style="font-size:28upx;color:rgba(78,102,88,1);" v-if="isRecord <2">{{ isRecord == 1 ? '正在录制' : '点击录制' }}</text>  
                    <image @tap.stop="onDeleteTap" src="../../static/record/delete@3x.png" style="border-radius: 36upx;width: 72upx;height: 72upx;box-shadow:0upx 4upx 8upx rgba(0,0,0,0.08);" v-else mode=""></image>  
                </view>  
                <image @tap.stop="onToggleRecordStatusTap" :src="iconPath" style="border-radius: 36upx;width: 72upx;height: 72upx;box-shadow:0upx 4upx 8upx rgba(0,0,0,0.08);" mode=""></image>  
            </view> -->  
        </view>  
        <view class="" @touchmove.stop.prevent="catchMove" v-if="isRecord === 1" style="position: fixed;top: 196upx;left:50%;transform: translateX(-50%);z-index: 9999;width: 480upx;height: 370upx;background:rgba(0,0,0,0.5);border-radius:8upx;">  
            <!-- <image src="../../static/images/microphone@3x.png" mode=""></image>  
            <image src="../../static/images/microphone@3x.png" mode=""></image> -->  
            <image src="../../static/images/recording.gif" mode="" style="width: 100%;height: 100%;border-radius: 8upx;"></image>  
        </view>  
    </view>  
</template>  

<script>  
const soundRecords = uni.getRecorderManager();  
const innerAudioContext = uni.createInnerAudioContext();  
innerAudioContext.autoplay = true;  

let timer = null;  
let minutes = 0;  
let seconds = 0;  
import { mapGetters } from 'vuex';  
export default {  
    data() {  
        return {  
            timing: '0分0秒',  
            text: '',  
            isRecord: 0,  
            iconPath: '../../static/record/startrecord@3x.png',  
            voicePath: '',  
            time: 0,  
            isPlay: false  
        };  
    },  
    computed: {  
        ...mapGetters(['getToken'])  
    },  
    mounted() {  

        console.log("1111")  
    },  
    onLoad() {  
        // this.$http.gettonken(this.getToken);  
    },  
    watch: {  
        "voicePath"(newValue) {  
            if(newValue){  
                console.log(this.time);  
                console.log(this.voicePath);  
                let voice = {  
                    voicePath: newValue,  
                    time: this.time  
                }  
                this.$emit("input",voice)  
            }  
        }  
    },  
    mounted(){  

        soundRecords.onStop(res => {  
            console.log(this.time);  
            clearTimeout(timer);  
            if(res.tempFilePath){  
                this.voicePath = res.tempFilePath  
                console.log(this.voicePath);  
            }else{  
                console.log("这里测试是否为空");  
            }  
            console.log('res: ' + JSON.stringify(res));  
        });  
        innerAudioContext.onEnded(() => {  
          this.isRecord = 2;  
          this.iconPath = '../../static/record/startplay@3x.png';  
          this.isPlay = false;  
          // this.timing = `0分0秒`;  
        });  
    },  
    methods: {  
        catchMove(){  
            return ;  
        },  
        onDeleteTap() {  
            this.voicePath = '';  
            this.timing = '0分0秒';  
            this.isRecord = 0;  
            minutes = 0;  
            seconds = 0;  
            this.isPlay = false;  
            this.iconPath= '../../static/record/startrecord@3x.png'  
            this.$modal({  
                title: "提示",  
                content: "删除成功",  
                showCancel: false  
            })  
        },  
        onToggleRecordStatusTap() {  
            switch (this.isRecord) {  
                case 0:  
                    this.onStartRecordTap();  
                    this.iconPath = '../../static/record/stoprecord@3x.png';  
                    break;  
                case 1:  
                    this.onStopRecordTap();  
                    this.iconPath = '../../static/record/startplay@3x.png';  
                    break;  
                case 2:  
                    if(!this.isPlay){  
                        this.isPlay = true;  
                        this.onPlayRecordTap();  
                        this.iconPath = '../../static/record/stopplay@3x.png';  
                    }else{  
                        this.toast("正在播放,请勿重复点击")  
                    }  

                    break;  
            }  
        },  
        onStartRecordTap() {  
            console.log('1: ');  
            soundRecords.start({  
                format: 'mp3'  
            });  
            this.isRecord = 1;  
            this.getTiming();  
        },  
        getTiming() {  
            if (this.isRecord == 1) {  
                if (minutes == 10 && seconds == 0) {  
                    clearTimeout(timer);  
                    minutes = 0;  
                    seconds = 0;  
                } else {  
                    this.time +=1;  
                    console.log(this.time);  
                    if (seconds == 59) {  
                        seconds = 0;  
                        minutes += 1;  
                    } else {  
                        seconds += 1;  
                    }  
                    this.timing = `${this.formatFull(minutes)}分${this.formatFull(seconds)}秒`;  
                    timer = setTimeout(() => {  
                        console.log(11);  

                        this.getTiming();  
                    }, 1000);  
                }  
            }  
        },  
        onStopRecordTap() {  
            soundRecords.stop();  
            console.log(this.time);  
            this.isRecord = 2;  
        },  
        onPlayRecordTap() {  
            if(this.isPlay){  
                this.toast("正在播放,请勿重复点击")  
                return ;  
            }  
            this.isPlay =  true;  
            if (this.voicePath) {  
                // this.isRecord = 3;  
                innerAudioContext.src = this.voicePath;  
                innerAudioContext.onPlay(() => {  
                  console.log('开始播放');  
                });  

            }else{  
                console.log('res: ' + this.voicePath);  
            }  
        }  
    }  
};  
</script>  

<style>  
.record-index {  
    height: 200upx;  
    width: 100%;  
    background: #ffffff;  
}  
/* .billow{  
    width: 6upx;  
    height: 16upx;  
    display: inline-block;  
    background: #66CC99;  
    position: absolute;top: 50%;transform: translateY(-50%);  
    animation: play 1.8s linear infinite;  
    border-radius: 3upx;  
}  
.billow1{  
    height: 20upx;  
    animation-delay: .8s;  
}  
.billow2{  
    height: 56upx;  
    animation-delay: 1s;  
}  
.billow3{  
    height: 50upx;  
    animation-delay: 1.2s;  
}  
.billow4{  
    height: 40upx;  
    animation-delay: 1.4s;  
}  
.billow5{  
    height: 30upx;  
    animation-delay: 1.6s;  
}  
.billow6{  
    height: 16upx;  
    animation-delay: 1.8s;  
}  
@keyframes play{  
    0% {  
        height: 20upx;  
    }  
    16% {  
        height: 56upx;  
    }  
    32% {  
        height: 50upx;  
    }  
    48% {  
        height: 40upx;  
    }  
    54% {  
        height: 30upx;  
    }  
    80% {  
        height: 16upx;  
    }  
    100% {  
        height: 20upx;  
    }  
} */  
</style>
2019-05-13 17:11 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

你这个华为机型闪退问题是必现的吗?
使用自定义组件模式测试看是否仍然复现?

  • 叶耳朵

    什么时候能解决啊 这个闪退问题很严重啊。很多需要语音的地方都要用到录音。从今年4月份就有人反映了 这都快2021年了 都没解决 到底咋办啊

    2020-12-31 16:47

  • 叶耳朵

    https://ask.dcloud.net.cn/question/59520

    2020-12-31 16:48

  • 叶耳朵

    改了arm以后还是闪退

    2020-12-31 16:48

  • DCloud_UNI_Anne

    回复 叶耳朵: 请您按报bug模板重新发帖,并提供简单可复现的完整示例,说明复现设备具体信息。否则无法复现就很难排查解决你的问题。

    2021-01-04 12:59

4***@qq.com

4***@qq.com - 学习前端的人

确实 录音就闪退 要不然 就没声音 然后退出程序重新进去 又有了

h***@gmail.com

h***@gmail.com

解决了吗,我也遇到了android第一次授权之后录音不是闪退就是录制的全是杂音。android7.0.1(vivo)

晚媚

晚媚

请问有解决吗

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