收藏
回答

安卓机页面卸载无法彻底销毁音频播放器实例?

InnerAudioContext.destroy()


  createAudio(src, loop = false) {
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.autoplay = false
    innerAudioContext.loop = loop
    innerAudioContext.src = src


    innerAudioContext.onPlay(() => {
      console.log('开始播放')
    })
    innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
    return innerAudioContext
  },
  playAudio(context) {
    context.play()
  },
  stopAudio(context) {
    context.stop()
  },
  destroyAudio(context) {
    context.destroy()
  }
 destoryAudios() {
        for (const key in this.audio) {
          Audio.destroyAudio(this.audio[key])
        }
        this.audio = null
      },

onUnload() {
      console.log('页面卸载了')
  
      this.stopAudio()
      this.destoryAudios()
      clearInterval(this.timer)
    },
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签