fix: run iOS audio primer synchronously in gesture handler, not in .then()

This commit is contained in:
Sterling Archer committed 2026-05-31 14:18:57 -07:00
1 parent 5f5507b538
commit d972122e27
1 file changed
+3 -2
+3 -2
View File
@@ -195,7 +195,7 @@ const SFX = (() => {
function primer() { function primer() {
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
ctx.resume().then(() => { try {
const osc = ctx.createOscillator(); const osc = ctx.createOscillator();
const gain = ctx.createGain(); const gain = ctx.createGain();
osc.connect(gain); osc.connect(gain);
@@ -203,7 +203,8 @@ const SFX = (() => {
gain.gain.setValueAtTime(0.0001, ctx.currentTime); gain.gain.setValueAtTime(0.0001, ctx.currentTime);
osc.start(ctx.currentTime); osc.start(ctx.currentTime);
osc.stop(ctx.currentTime + 0.001); osc.stop(ctx.currentTime + 0.001);
}).catch(() => {}); } catch(e) {}
if (ctx.state === 'suspended') ctx.resume().catch(() => {});
} }
function unlock() { function unlock() {
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();