Can you check with this snapshot and let me know if it is fixed? I couldnât reproduce this on a local device (i get 60 fps), but i think i know where it might come from:
Thank you so much for the fix. After testing it a couple of times, I think it is fixed now. Glad that is over with. It was literally driving me nuts trying to pinpoint the root cause of the performance drop.
This may be related to the above issue. Hope you donât mind me continuing the conversation here. In iOS Safari, stuff like this doesnât work (which works in Android).
Hmm, it still doesnât work. It still pauses on quit but doesnât resume. There is no error now though. Not sure if I am getting this right, it appears both the promises arenât resolved at all (but the audio did get paused). And if you try to quit a second time, the two pause promises got resolved at the same time (but still no resume promise).
This is quite a headache. I may just use the setVolume method if it doesnât burn that much resources in the background.
EDIT: It appears the audio gets paused immediately on losing visibility without the need for pauseAsync().
The previous forum post should also be a good point of reference.
As much as I hate to admit, I have switched to howler.js for my project for now. And even there, the problem exists. There seems to be some wonky interactions with AudioContext resuming and suspending in iOS. Safari doesnât allow resuming without a user gesture.
From all of my tests - this seems like a bug in safari that we canât overcome. Or at least I havenât found a proper solution. With the current implementation in the draft PR i can switch between tabs and continue hearing audio, but going to the home screen and back to the scene - and then unmuting the scene again, doesnât help with the audio. Funny enough, when navigating to a new tab after that, the audio starts playing. This is why i think itâs a safari bug and not some limitation or a serious issue in the code. I can and will continue experimenting, but i am not sure what else i can add without starting to add hacks that I donât want to see (and not even sure they will help)
That seems to be the case for me as well. In Safari, AudioContext.state becomes interrupted when returning to home screen and it appears calling suspend() or resume() during that state makes it throw an error.
This is my solution at the moment. Howler.ctx is just AudioContext.
document.addEventListener("visibilitychange", () => {
if (!Howler.ctx) return;
if (document.hidden && Howler.ctx.state === "running")
Howler.ctx.suspend();
else if (Howler.ctx.state === "suspended") Howler.ctx.resume();
});
Of course, the audio still doesnât resume on return. But I can easily resume it by binding resume() to a button. This appears to work consistently without any funny behavior.