在ios上播放一次音频后,再次点击播放该音频,无法调用 innerAudioContext.onPlay,在android手机上没有问题。
wxml:
<view class=‘color-white audio pull-left flex flex-vc’ data-url=’{{audioUrl}}’ bindtap=‘play2’>
<view class=‘icon-play2’></view>
<text class=‘color-white’ wx:if="{{audioStatus}}">播放中</text>
<text class=‘color-white’ wx:else>{{duration}}s</text>
</view>
js:
const innerAudioContext2 = wx.createInnerAudioContext()
//预听录音
play2: function (e) {
console.log(“预听录音”)
var that = this;
innerAudioContext2.autoplay = true
innerAudioContext2.src = e.currentTarget.dataset.url;
},
onLoad: function (options) {
innerAudioContext2.onPlay(() => {
console.log(‘开始播放’)
that.setData({
audioStatus: true,
})
})
innerAudioContext2.onEnded(() => {
console.log(‘播放结束’)
that.setData({
audioStatus: false,
})
})
innerAudioContext2.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})
},
ios真机上打印信息如下图,第一次点击播放执行了,第二次点击播放时没有执行innerAudioContext2.onPlay:
在Android手机上如图所示: