小程序怎么按顺序播放音频?
发布于 5 年前 作者 yuanping 5598 次浏览 来自 官方Issues

一个数组中有六条音频链接,怎么按顺序在小程序中播放出来?

pop出来不会从第一个开始,也只是播放其中一个,用循环的话所有音频会一起播放,求助有什么办法可以一个一个按顺序播放?

3 回复

在end回调事件里面播放下一个

let innerAudioContext = wx.createInnerAudioContext()
let currentIndex = 0;
let aa = ['xx', 'xx', 'xx', 'xx', 'xx', 'xx']
innerAudioContext.autoplay = true
 
innerAudioContext.onPlay(() => {
  console.log('开始播放')
})
innerAudioContext.onError((res) => {
  console.log(res.errMsg)
  console.log(res.errCode)
})
innerAudioContext.onEnded((res) => {
  if(currentIndex < aa.length){
      innerAudioContext.src = aa[currentIndex++];
  }
})
 
innerAudioContext.src = aa[currentIndex]

不知道审核能不能过呢,(手动狗头

直接用for循环数组,然后播放不可以么?

然后判断下每个的播放状态,结束后再下一条~

回到顶部