微信小程序添加音效createInnerAudioContext

可以查看微信小程序api文档中

     //添加音效
          const innerAudioContext = wx.createInnerAudioContext()
          innerAudioContext.autoplay = true  // 是否自动开始播放,默认为 false
          innerAudioContext.loop =false  // 是否循环播放,默认为 false
          wx.setInnerAudioOption({ // ios在静音状态下能够正常播放音效
            obeyMuteSwitch: false,   // 是否遵循系统静音开关,默认为 true。当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。
            success: function(e) {
              console.log(e)
              console.log('play success')
            },
            fail: function(e) {
              console.log(e)
              console.log('play fail')
            }
          })
          innerAudioContext.src = '/utils/gold.mp3';  // 音频资源的地址
          innerAudioContext.onPlay(() => {  // 监听音频播放事件
            console.log('开始播放')
          })
          innerAudioContext.onError((res) => { // 监听音频播放错误事件
            console.log(res.errMsg)
            console.log(res.errCode)
          })
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值