From b47e11ef48432435c7e86eb54d91752407b7245d Mon Sep 17 00:00:00 2001 From: Eduard Prigoana Date: Sat, 14 Feb 2026 18:01:25 +0000 Subject: [PATCH] fix(iOS): don't set isInitialized flag when skipping Web Audio on iOS Previously, the code was setting isInitialized = true on iOS even though no AudioContext was created. This caused isReady() to return true, which led other code to try to use the non-existent audio context. Now isInitialized remains false on iOS, so isReady() returns false and the code properly falls back to using the standard HTMLAudioElement APIs. --- js/audio-context.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/audio-context.js b/js/audio-context.js index a845c93..19ce703 100644 --- a/js/audio-context.js +++ b/js/audio-context.js @@ -133,6 +133,8 @@ class AudioContextManager { if (this.isInitialized) return; if (!audioElement) return; + this.audio = audioElement; + // Detect iOS - skip Web Audio initialization on iOS to avoid lock screen audio issues // iOS suspends AudioContext when screen locks, and MediaSession controls don't count // as user gestures to resume it, causing audio to play silently @@ -140,13 +142,12 @@ class AudioContextManager { const isIOS = /iphone|ipad|ipod/.test(ua) || (ua.includes('mac') && navigator.maxTouchPoints > 1); if (isIOS) { console.log('[AudioContext] Skipping Web Audio initialization on iOS for lock screen compatibility'); - this.isInitialized = true; // Mark as initialized to prevent repeated attempts + // Don't set isInitialized - let it remain false so isReady() returns false + // This prevents other code from trying to use the non-existent audio context return; } try { - this.audio = audioElement; - const AudioContext = window.AudioContext || window.webkitAudioContext; this.audioContext = new AudioContext(); @@ -313,10 +314,10 @@ class AudioContextManager { } /** - * Check if initialized + * Check if initialized and active */ isReady() { - return this.isInitialized; + return this.isInitialized && this.audioContext !== null; } /**