Android系统下InnerAudioContext第一次点击播放无声音
发布于 4 年前 作者 mintao 5652 次浏览 来自 问答

使用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>

3 回复

Android第一次播放时,其实是有播放出声音(大概几百毫秒,能听到一点声音),然后就播放结束了,不知道什么原因?iOS系统能播放完整。

我用分享的代码片段(wechatide://minicode/98d01233f77b1340c6ff4579dfdee6f6)可以播放。

在项目(/receive/receive-pro.js)中却失败了,能分析是什么原因吗?  谢谢

补充运行日志

// 第一次点击播放按钮日志

https://host/audio/oAJ2V5OiO_nfgpZ2Wr0aLIlzZ5xE/2018/03/20/05fe550987da477a835065e0beb88089.wav

onCanplay

onWaiting

onCanplay

开始播放

播放结束

// 第二次点击播放按钮日志

https://host/audio/oAJ2V5OiO_nfgpZ2Wr0aLIlzZ5xE/2018/03/20/05fe550987da477a835065e0beb88089.wav

onCanplay

onWaiting

onCanplay

开始播放

播放结束

回到顶部