From 0e6f4852e52e18f7249a333db64deef611d5969a Mon Sep 17 00:00:00 2001 From: Dallas Groot Date: Fri, 10 Apr 2026 19:44:55 -0700 Subject: [PATCH] visualizer fix --- Shared/Audio/AudioPlayer.swift | 7 +++++-- iOS/Views/Companion/SmartCrossfadeManager.swift | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Shared/Audio/AudioPlayer.swift b/Shared/Audio/AudioPlayer.swift index 045f106..36f1462 100644 --- a/Shared/Audio/AudioPlayer.swift +++ b/Shared/Audio/AudioPlayer.swift @@ -148,17 +148,20 @@ class AudioPlayer: NSObject, ObservableObject { } private func resumeVisTimers() { - guard isPlaying else { return } + // Always reinstall time observers — they were removed on background regardless + // of play state. Without this, currentTime is frozen after background+pause+play. reinstallTimeObserver() if isUsingCrossfade { SmartCrossfadeManager.shared.resumeFromBackground() } + // Only restart vis timers if actually playing + guard isPlaying else { return } if isUsingOfflineVis { startOfflineVisSync() } else if !isUsingCrossfade { startLevelSimulation() } - alog("Foreground: timers + observers resumed (crossfade=\(isUsingCrossfade) offlineVis=\(isUsingOfflineVis))") + alog("Foreground: observers + vis timers resumed (crossfade=\(isUsingCrossfade) offlineVis=\(isUsingOfflineVis))") } private func removeTimeObserver() { diff --git a/iOS/Views/Companion/SmartCrossfadeManager.swift b/iOS/Views/Companion/SmartCrossfadeManager.swift index 356ff6d..4ca1206 100644 --- a/iOS/Views/Companion/SmartCrossfadeManager.swift +++ b/iOS/Views/Companion/SmartCrossfadeManager.swift @@ -196,6 +196,9 @@ class SmartCrossfadeManager: ObservableObject { func resume() { activePlayer.play() if isCrossfading { standbyPlayer.play() } + // Reinstall the time observer if it was removed by suspendForBackground() + // (happens when app is backgrounded while paused then brought back to foreground) + if timeObserver == nil { installTimeObserver() } } func seek(to time: TimeInterval) {