音频播放,先下载到本地再播放

This commit is contained in:
2022-01-30 18:20:48 +08:00
parent 83061d7c8e
commit 50cb518620

View File

@@ -32,20 +32,27 @@
// 播放语音消息
onPlayMsg() {
console.log('播放', this.msg.remote);
let innerAudioContext = uni.createInnerAudioContext()
innerAudioContext.src = this.msg.remote
if (this.audioContextPaused) {
innerAudioContext.play()
this.audioContextPaused = false
return
}
innerAudioContext.stop()
innerAudioContext.onStop(resStop => {
console.log('停止');
this.audioContextPaused = true
})
innerAudioContext.onError(err => {
console.log(err);
uni.downloadFile({
url: this.msg.remote,
success: (res) => {
if (res.statusCode === 200) {
let innerAudioContext = uni.createInnerAudioContext()
innerAudioContext.src = res.tempFilePath
if (this.audioContextPaused) {
innerAudioContext.play()
this.audioContextPaused = false
return
}
innerAudioContext.stop()
innerAudioContext.onStop(resStop => {
console.log('停止');
this.audioContextPaused = true
})
innerAudioContext.onError(err => {
console.log(err);
})
}
}
})
}
}