微信小程序背景音乐InnerAudioContext 微信额外提示音

  • 定义一个页面全局变量(在onLoad同级)
innerAudioContext: null,
  • 在onReady生命周期
/* 
 * 生命周期函数--监听页面初次渲染完成
*/
  onReady:function() {
    this.innerAudioContext = wx.createInnerAudioContext()
    this.innerAudioContext.autoplay = true
    this.innerAudioContext.loop = true
    this.innerAudioContext.src = 'https://sharefs.ali.kugou.com/202110282316/5bc14f9bebf1a12a0ba4451d74689455/KGTX/CLTX001/fd0c50ca69d3529c23f68b38d6d239ea.mp3'
    this.innerAudioContext.onPlay(() => {
      console.log('开始播放')
    })
    this.innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
  },   
  • 在生命周期销毁或者卸载时停止(看自己需求)
onHide: function () {
    console.log('waiting页面隐藏')
    this.innerAudioContext.pause()
},

onUnload: function () {
    console.log('waiting页面卸载')
    this.innerAudioContext.pause()
  },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值