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 }