欢迎体验
小程序效果如图
实现步骤
将mp3保存到云存储
需要注意的是,此处贴了 ID 不可以直接用于backgroundAudioManager播放
需要将fileID转临时路径才可以播放
```
wx.downloadFile({
url: fileID, //mp3的fileID
success: res => {
console.log('ok')
resolve(res.tempFilePath)
}
})
```
最后使用 backgroundAudioManager 播放即可
```
playVoice(title,src){
console.log('src:',title,src)
backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = title
backgroundAudioManager.epname = title
backgroundAudioManager.singer = title
backgroundAudioManager.coverImgUrl = 'cloud://yuludev-4e0n9.7975-yuludev-4e0n9-1301573818/mabaoguo/avatar.png'
// 设置了 src 之后会自动播放
backgroundAudioManager.src = src
backgroundAudioManager.onPause( ()=>{
this.playVoice(src)
})
backgroundAudioManager.onStop( ()=>{
this.playVoice(src)
})
backgroundAudioManager.onError( (e)=>{
console.error(e)
})
backgroundAudioManager.onCanplay( (e)=>{
console.log('加载完毕')
wx.hideLoading({
success: (res) => {},
})
})
},
```
感谢您的阅读~