今天在华为nova 4e 型号MAR-AL00 安卓9版本测试, 调用录音api时,app闪退了,但是在小米手机测试,不会出现,使用的老模板模式编译模式,代码如下:
语音描述(录音时长最大为10分钟)
删除录音
{{
isRecord === 0?'点击录制':'录制中'
}}
{{
timing+(isRecord == 2?' 点击播放':' 正在播放')
}}
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);
}
}
}
};
.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;
}
} */