Multiple AdvancedAudioPlayers will stop when setPosition is called
Closed this issue · 7 comments
I'm having issues when using more that 5 AdvancedAudioPlayers. More specifically, they all stop playing after calling setPosition multiple times.
In this example we have 6 AdvancedAudioPlayers running, and if you click the "random seek" button 4 times, the playback will stop. Check your browser console for following logs:
It seem that the first initialized AdvancedAudioPlayers constantly gets out of sync and playback will stop? While things seem to be stopped player.isPlaying() keeps reporting that is playing?
You can play with the number of initialized AdvancedAudioPlayers by changing /processor.js:15
The output of the players in processAudio is not mixed together. Currently your code overwrites the contents of the outputBuffer for every player. You need something like this:
let silence = true;
for (const player of this.player) {
if (player.processStereo(outputBuffer.pointer, !silence, ...)) silence = false;
}
if (silence) this.Superpowered.memorySet(outputBuffer.pointer, 0, ...);
I also see this issue and made a sandbox to demonstrate the issue in isolation: https://codesandbox.io/s/loving-wright-4m6qnp. I've experimented with:
- Stopping the players before seeking, seeking, then resuming playback
- Trying to cache the position with cachePosition() before seeking to it
Still seeing the same issue, sometime it plays for a second or so before cutting out after calling player.setPosition()
@gaborszanto I've integrated your code in my example and the problem still persists. In my "real" app, everything is wired via multiple StereoMixer and we have the same issue.
I've also tried those workarounds mentioned by @dodds-cc without success.
While the mixing problems are still valid, I discovered a memory allocation bug. When a lot of allocations happen in a very short time, the allocator couldn't keep up. Working on a fix.
Please update to the latest Superpowered version and check if it fixes it.
@gaborszanto I've updated my example above and it seems to be resolved, thank you. It also seems to be resolved in my actual project, which is running around 12 player instances through various StereoMixer classes. I'm going to test it on some lower performance devices.
@hugorodrigues How did it go for your project?
@dodds-cc @gaborszanto Everything is working as expected now! Thank you!
