请大神回复:
const app = getApp()
Page({
data:{
isPlayingMusic:false,
},
bgm:null,
music_url:'/images/易言 - 太阳.mp3',
music_coverImgUrl:'/images/50.jpg',
OnReady:function(){
this.bgm = wx.getBackgroundAudioManager()
this.bgm.title='太阳'
this.bgm.epname='abc'
this.bgm.singer='易言'
this.bgm.coverImgUrl = this.music_coverImgUrl
this.bgm.onCanplay(()=>{
this.bgm.pause()
})
this.bgm.src = this.music_url
},
play:function(){
if(this.data.isPlayingMusic){
this.bgm.pause()
}else{
this.bgm.play()
}
this.setData({
isPlayingMusic: ! this.data.isPlayingMusic
})
}
})
bgm未被实例化,OnReady内方法未被执行
onReady大小写有问题,另外调用方法时最好判断一下对象是否为空
你自行检查一下这段,试试