AI助手支持GPT4.0
js中出现 Cannot read property 'play' of nul?Cannot read property'play' of nul appears in js?
js中出现 Cannot read property 'play' of nul?
请大神回复:
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
})
}
})
请大神回复: 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内方法未被执行