政务网站建设浙江,免费招聘的网站,网络优化工具,形象设计师培训学校uniapp对接融云IM即时通讯#xff0c;语音消息无法播放 问题背景解决方案1.本地音频播放2.远程音频播放 问题背景
最近使用uniapp对接融云的即时通讯sdk#xff0c;发送语音消息后#xff0c;本地音频#xff08;local#xff09;和远程音频#xff08;remote#xff0… uniapp对接融云IM即时通讯语音消息无法播放 问题背景解决方案1.本地音频播放2.远程音频播放 问题背景
最近使用uniapp对接融云的即时通讯sdk发送语音消息后本地音频local和远程音频remote都无法正常播放 播放local时uniapp的音频api返回了{errCode -5} 播放remote时uniapp的音频api返回了{errCode -99}
解决方案
1.本地音频播放 经过验证融云返回的音频local地址是以file://开头的平台绝对路径uniapp播放该地址时报错code-5有可能是权限问题app无法读取这个路径中的数据 解决方法使用uni.saveFile将local的地址文件保存到该应用的沙盒目录中 async created() {let local file:///data/user/0/xxxxxxx.aaclet path await this.getLocalUrl(local)
},
methods: {getLocalUrl(local) {let that this;return new Promise((reslove,reject) {uni.saveFile({tempFilePath: local,success: (res) {reslove(res.savedFilePath)},fail: (err) {console.log(saveFile fail , err);reject(err)}})})}
}
使用以上方法成功解决本地音频无法播放的问题 【注意】uni.saveFile每次都会重新保存一个文件需要自己处理一下避免撑爆存储空间
2.远程音频播放 经验证使用uniapp音频api播放remote音频时会有一段时间没有反应随后报错-99,感觉是remote地址中有一些特殊字符导致音频api解析失败 解决方法使用encodeURI对远程地址进行转义
let remote https://bucket7-a-3.ronghub.com/xxxx.aac?exxxtokenxxxx
let path encodeURI(remote)