Resume AudioContext on visibilitychange to fix SFX on mobile after tab switch

This commit is contained in:
justin committed 2026-05-20 20:36:39 -07:00
1 parent c2583cd36d
commit f5c3cb9145
1 file changed
+7
+7
View File
@@ -120,6 +120,13 @@ const SFX = (() => {
return ctx;
}
/* Resume AudioContext when user returns to the page on mobile */
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
ctx.resume();
}
});
/* Core: play a tone with envelope */
function tone(freq, type, vol, attack, sustain, release, when) {
const c = getCtx();