定义一个页面全局变量(在onLoad同级)
innerAudioContext: null,
在onReady生命周期
/* * 生命周期函数--监听页面初次渲染完成*/onReady:function() {this.innerAudioContext = wx.createInnerAudioContext()this.innerAudioContext.autoplay = truethis.innerAudioContext.loop = truethis.innerAudioContext.src = 'https://sharefs./10282316/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()},