录音
onLoad(options) { let that=this this.recorderManager = uni.getRecorderManager(); //创建录音管理 }, methods:{ //开始录音 startRecord(index){ let that=this uni.authorize({ scope:"scope.record", success(){ uni.showToast({ icon:"none", title:"开始录音" }) that.recorderManager.start(); that.recorderManager.onStart() console.log("录音执行") }, fail() { uni.showModal({ title: '提示', content: '您未授权录音,功能将无法使用', showCancel: true, confirmText: "授权", confirmColor: "#52a2d8", success(res) { if(res.confirm){ uni.openSetting({ }) }else{ } } }) } }) }, //结束录音 endRecord(index){ let that=this uni.stopRecord({ success:function(e){ that.recorderManager.stop(); that.recorderManager.onStop((res=>{ that.audioTempFile=res.tempFilePath that.uploadAudio(index) })) } }) } }
播放音频文件
onLoad(options) { let innerAudioContext = uni.createInnerAudioContext(); //创建音频文件 innerAudioContext.autoplay = false; //不自动播放 innerAudioContext.src = this.audioSrc; //音频文件链接 this.innerAudioContext=innerAudioContext }, methods:{ //开始音频文件 startAudio(){ this.innerAudioContext.play(() => { console.log('开始播放'); }); this.innerAudioContext.onError((res) => { console.log(res.errMsg); console.log(res.errCode); }); }, //结束音频 endAudio(){ let that=this uni.showToast({ icon:"none", title:"已结束" }) this.innerAudioContext.stop(() => { console.log('已暂停'); }); this.innerAudioContext.onError((res) => { console.log(res.errMsg); console.log(res.errCode); }); }, //暂停音频文件 pauseAudio(desc){ let that=this uni.showToast({ icon:"none", title:desc }) this.innerAudioContext.pause(() => { console.log('已暂停'); }); this.innerAudioContext.onError((res) => { console.log(res.errMsg); console.log(res.errCode); }); } }