Android系统下InnerAudioContext第一次点击播放无声音
使用innerAudioContext play方法播放语音时Android系统第一次点击无声音,第二次点击可正常播放。iOS系统正常。
第一次innerAudioContext回调方法都正确,就是没声音。第二次点击播放可正常播放,有声音,回调函数与第一次回调流程一致。
var voiceSrc = event.currentTarget.dataset.src; 比较怪异的是这一句代码使用固定的连接地址第一次播放就正常。难道dataset 方式参数变了?从日志打印来看语音文件链接是正确的,可正常下载。
如:
var voiceSrc = ‘https://host/audio.wav’;
API使用方式如下:
// list.js
const innerAudioContext = wx.createInnerAudioContext();
toPlayVoice: function (event) {
var voiceSrc = event.currentTarget.dataset.src;
// 在这里日志打印 voiceSrc 连接是正确的,浏览器访问可正常下载
innerAudioContext.src = voiceSrc;
innerAudioContext.play()
},
onLoad: function() {
//录音的回调写在onLoad就只调用一次
innerAudioContext.onPlay(() => {
console.log(‘开始播放’)
})
innerAudioContext.onError((res) => {
console.log(“error errMsg” + res.errMsg)
console.log(“error errCode” + res.errCode)
})
innerAudioContext.onWaiting(() => {
console.log(“onWaiting”)
})
innerAudioContext.onCanplay(() => {
console.log(“onCanplay”)
})
innerAudioContext.onEnded(() => {
console.log(‘播放结束’);
})
}
// list.wxml
<template name=“receive_get_item_template”>
<button type=“primary” data-src=“{{item.path}}”hover-class=‘none’ bindtap=‘toPlayVoice’>{{item.duration}}</button>
</template>
