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])
},