const recorderManager = wx.getRecorderManager()
recorderManager.onStart(() => {
console.log('recorder start')
})
recorderManager.onResume(() => {
console.log('recorder resume')
})
recorderManager.onPause(() => {
console.log('recorder pause')
})
recorderManager.onStop((res) => {
console.log('recorder stop', res)
const { tempFilePath } = res
wx.playVoice({
filePath: tempFilePath,
fail:function(ret){
console.log(ret)
},
success:function(){
console.log('播放成功')
}
})
})
recorderManager.onFrameRecorded((res) => {
const { frameBuffer } = res
console.log('frameBuffer.byteLength', frameBuffer.byteLength)
})
const options = {
duration: 5000,
sampleRate: 44100,
numberOfChannels: 1,
encodeBitRate: 192000,
format: 'mp3',
frameSize: 50
}
recorderManager.start(options)
我的手机是一加3T,微信版本是6.5.16版本
网友回复:
你好,使用 getRecorderManager 录制的音频,需要使用 createInnerAudioContext 接口来播放 https://mp.weixin.qq.com/debug/wxadoc/dev/api/createInnerAudioContext.html
好吧,我就猜到了
请问如何用createInnerAudioContext 播放录制的音频呢,src不是别tempfilepath 报
Failed to set src, the src undefined is invalid.;at pages/myPage page playVoice function
TypeError: Failed to set src, the src undefined is invalid.
我打印的tempfile是wxfile://tmp_*.m4a
这是我的播放代码
console.log("tempfilepath:"+tempFilePath);
innerAudioContext.src = tempFilePath;
innerAudioContext.play();
兄弟
innerAudioContext.src = tempFilePath.tempFilePath;
第一个tempFilePath为录音返回的OBJECT。希望能用。我在开发工具上没问题,但在真机上却没反应
var filepath = this.data.filepath;
console.log(filepath);
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.src = filepath.tempFilePath;
innerAudioContext.onPlay(() => {
console.log('开始播放')
});
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
});
innerAudioContext.play();
兄弟如果方便留个QQ或微信号,一起交流交流
qq:467516920
在真机上确实没反应 把src改成网络资源就没问题了