fix: restore mobile Web Audio SFX on iOS/Android

This commit is contained in:
Sterling Archer
2026-05-31 14:01:11 -07:00
parent 5b18f9bda1
commit 0adbdfc106
+7 -5
View File
@@ -189,19 +189,21 @@ const SFX = (() => {
function getCtx() { function getCtx() {
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
if (ctx.state === 'suspended') ctx.resume(); if (ctx.state === 'suspended') ctx.resume().catch(() => {});
return ctx; return ctx;
} }
function unlock() { function unlock() {
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
if (ctx.state === 'suspended') ctx.resume().then(() => {}); if (ctx.state === 'suspended') ctx.resume().catch(() => {});
} }
document.addEventListener('touchstart', unlock, { once: true, passive: true }); document.addEventListener('touchstart', unlock, { passive: true });
document.addEventListener('pointerdown', unlock, { once: true, passive: true }); document.addEventListener('touchend', unlock, { passive: true });
document.addEventListener('pointerdown', unlock, { passive: true });
document.addEventListener('click', unlock, { passive: true });
document.addEventListener('visibilitychange', () => { document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') { if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
ctx.resume(); ctx.resume().catch(() => {});
} }
}); });