小程序录音(getRecorderManager)和播放录音(createInnerAudioContext)的踩坑记录
问题描述
使用默认的format,即aac格式,在真机上返回的音频格式为m4a
- 手机型号: 华为荣耀30
- 微信版本: 8.0.9
const recorderManager = wx.getRecorderManager();
recorderManager.start();
recorderManager.onStop(res => {console.log(res);
});
解决方案
- 后台支持m4a格式
- 使用 format: ‘mp3’
第二个坑 《不能播放》 (通过 wx.downloadFile 解决)
问题描述
安卓手机 通过录音api生成的音频文件,上传至自己后台后,再使用createInnerAudioContext api播放时,报错 format error
cosnt innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.src = recordAudioSrc;
innerAudioContext.play();
innerAudioContext.onError(err => {console.log('播放错误... ', res);
});
解决方案
- 由后台返回文件流而不是文件访问地址
- 安卓使用 wx.downloadFile 将文件下载至本地后播放,ios使用 innerAudio 的api播放,请参考代码片段 https://developers.weixin.qq.com/s/ncTJjPmn7qig


ios只支持在线播放
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
