4990关注14966浏览
使用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>
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多> -
画心
17人对此回答表示赞同
补充运行日志
展开170回复分享发布于 6年前评论(0)
收起评论
-
Mason
16人对此回答表示赞同
麻烦给个相关的代码片段,我们定位下问题
展开160回复分享发布于 6年前评论(0)
收起评论
-
思念在大脑里裸奔
9人对此回答表示赞同
Android第一次播放时,其实是有播放出声音(大概几百毫秒,能听到一点声音),然后就播放结束了,不知道什么原因?iOS系统能播放完整。
展开90回复分享发布于 6年前评论(0)
收起评论