小程序可以实现多音频同时播放吗?
发布于 5 年前 作者 vmeng 12325 次浏览 来自 问答

小程序可以实现多音频同时播放吗?

wx.createInnerAudioContext API可以创建多个实例吗?有什么限制吗?csdn上看到说最多只能5个,有官方文档说明吗?

3 回复

目前是没有这方面的限制

目前解决方法只有如下:

const innerAudioContext1 = wx.createInnerAudioContext()
innerAudioContext1.src = 'audio/piano/c4.mp3'
 
 const innerAudioContext2 = wx.createInnerAudioContext()
 innerAudioContext2.src = 'audio/piano/e4.wav'
 
 const innerAudioContext3 = wx.createInnerAudioContext()
 innerAudioContext3.src = 'audio/piano/g4.wav'
 
 innerAudioContext1.play()
 innerAudioContext2.play()
 innerAudioContext3.play()

但个人认为这不是非常严格的“同时播放”。

JS是单线程的,三个音频顺序执行了,只是时间差别在ms级听不出来先后而已。

为啥要创建多个?  直接换src不就可以了

回到顶部