js中出现 Cannot read property 'play' of nul?

小程序 文章 2021-12-16 10:00 752 0 全屏看文

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 }) } })

回答:

Weichat:

bgm未被实例化,OnReady内方法未被执行

莫若:感谢!
xxxidream:

onReady大小写有问题,另外调用方法时最好判断一下对象是否为空

莫若:感谢!
A.伙伴营销拓客:

你自行检查一下这段,试试

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
小程序是否有那种一次性授权后,后面都能长期收到服务通知的功能?
小程序发布不了 扫码后一直显示已确认成功? wxabfab58e7475b1f7
新注册域名 ,备案成功后,测试链接 提示:发布违规,被多人举报! 这个如何避免?严重用户使用!
小程序已经绑定到开放平台,但小程序jscode2session方法依然不返回unionid,有解吗?
如何将一维数组变成二维数组?
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8551
问题? 8269
如何快速搭建抽奖助手小程序(无需代码知识) 5330
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6699
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5983
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5539
如何解决渲染层网络错误Failed to load media? 16783
小程序找号找回 释放昵称? 2797
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2665
删除部分微信用户个人数据的通知,怎么删除? 5846