Resume AudioContext on visibilitychange to fix SFX loss after backgrounding app

This commit is contained in:
justin committed 2026-05-20 20:32:14 -07:00
1 parent 18809b6b86
commit c1d6eab38e
1 file changed
+5
+5
View File
@@ -126,6 +126,11 @@ const SFX = (() => {
} }
document.addEventListener('touchstart', unlock, { once: true, passive: true }); document.addEventListener('touchstart', unlock, { once: true, passive: true });
document.addEventListener('pointerdown', unlock, { once: true, passive: true }); document.addEventListener('pointerdown', unlock, { once: true, passive: true });
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
ctx.resume();
}
});
/* Core: play a tone with envelope */ /* Core: play a tone with envelope */
function tone(freq, type, vol, attack, sustain, release, when) { function tone(freq, type, vol, attack, sustain, release, when) {