一样的,我在uni-app官网复制录音管理里面的
<template>
<view>
<button @tap="startRecord">开始录音</button>
<button @tap="endRecord">停止录音</button>
<button @tap="playVoice">播放录音</button>
</view>
</template>
<script>
const recorderManager = uni.getRecorderManager();
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
export default {
data: { text: 'uni-app', voicePath: '' },
onLoad() {
let self = this;
recorderManager.onStop(function(res) {
console.log('recorder stop' + JSON.stringify(res));
self.voicePath = res.tempFilePath;
});
},
methods: {
startRecord() {
console.log('开始录音');
recorderManager.start();
},
endRecord() {
console.log('录音结束');
recorderManager.stop();
},
playVoice() {
console.log('播放录音');
if (this.voicePath) {
innerAudioContext.src = this.voicePath;
innerAudioContext.play();
}
}
}
};
</script>
<style></style>
测试手机为华为p20和荣耀畅玩7C,下面是显示的错误信息,请问有没有解决方案
17:36:12.482 开始录音 at pages/tabbar/tabbar-1/tabbar-1.vue:23
17:36:16.735 录音结束 at pages/tabbar/tabbar-1/tabbar-1.vue:27
17:36:16.828 recorder stop{"tempFilePath":"_doc/uniapp_temp_1553333952072/recorder/1553333957221.aac"} at pages/tabbar/tabbar-1/tabbar-1.vue:17
17:36:20.086 播放录音 at pages/tabbar/tabbar-1/tabbar-1.vue:31
17:36:20.148 Uncaught (in promise) NotSupportedError: Failed to load because no supported source was found. at __uniappservice.html:0
RunUpApp
不是兼容性问题测试了华为荣耀9 和小米9都一样
2019-03-20 09:58