音频在开发者工具和苹果手机上可以播放,安卓不行
发布于 5 年前 作者 sxu 20141 次浏览 来自 问答

wx.createInnerAudioContext()在微信开发者工具和苹果手机上可以播放,在安卓手机上不能播放。

const innerAudioContext = wx.createInnerAudioContext()

//音频播放

audio_click: function (e) {

var that = this;

var index = e.currentTarget.dataset.id;

var src = e.currentTarget.dataset.src;

var audioId = that.data.totalArr[index].name;

audioId = innerAudioContext;

audioId.volume = 1;

audioId.obeyMuteSwitch = false;

audioId.autoplay = true;

if (that.data.audio_index != null && that.data.audio_index != index){

that.data.totalArr[that.data.audio_index].isPlay = false;

}

if (that.data.totalArr[index].isPlay == false) {

audioId.src = src;

audioId.play();

that.data.totalArr[index].isPlay = true;

that.setData({

totalArr: that.data.totalArr

})

} else if (that.data.totalArr[index].isPlay == true) {

audioId.src = null;

that.data.totalArr[index].isPlay = false;

that.setData({

totalArr: that.data.totalArr,

audio_index: index

})

audioId.stop();

}

audioId.onEnded(() => {

that.data.totalArr[index].isPlay = false;

that.setData({

totalArr: that.data.totalArr,

audio_index: index

})

audioId.stop();

audioId.src = null;

})

audioId.onPlay(() => {

var total = parseInt(audioId.duration);

var minute = parseInt(total / 60);

if (minute < 10) {

minute = ‘0’ + minute;

}

var second = total % 60;

if (second < 10) {

second = ‘0’ + second;

}

total = minute + “:” + second;

that.data.totalArr[index].slider_max = total;

that.setData({

totalArr: that.data.totalArr

})

audioId.onTimeUpdate(() =>{

console.log(audioId.currentTime)

})

})

console.log(that.data.totalArr[0])

console.log(that.data.totalArr[1])

},

3 回复

音频这个问题太多了 希望官方可以尽快完善

你好,其实像这种无法播放的事件,可以加个音频播放错误事件,打印下错误回调信息查看下,针对问题来排查原因的

errCode:67,err:decode audio fail        10001

回到顶部