From a1cf0a00b332d72a1697a7edadb834b903137654 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Oct 2026 17:40:59 -0700 Subject: [PATCH] ios: prepare the next track only after the current one is playing and fully cached Co-Authored-By: Claude Sonnet 5.5 --- ios/Stemify/Playback/PlaybackManager.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/Stemify/Playback/PlaybackManager.swift b/ios/Stemify/Playback/PlaybackManager.swift index 2302488..c8f5a1f 100644 --- a/ios/Stemify/Playback/PlaybackManager.swift +++ b/ios/Stemify/Playback/PlaybackManager.swift @@ -654,7 +654,11 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable { guard let i = upcomingIndex() else { return } let item = queue[i] nextTask = Task { @MainActor [weak self] in - try? await Task.sleep(nanoseconds: 4_000_000_000) // let the current track's stems get a head start + // Don't compete with the current track: wait until it is playing and fully cached. + while let self, !Task.isCancelled { + if let cur = self.current?.track, self.engine.playing, !self.engine.buffering, self.playableOffline(cur) { break } + try? await Task.sleep(nanoseconds: 1_000_000_000) + } guard let self, !Task.isCancelled else { return } // The normal load path reports failures. guard let (s, entry) = try? await self.openDetached(item.track, 0) else { return }