ios: prepare the next track only after the current one is playing and fully cached
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4277688a38
commit
a1cf0a00b3
1 file changed
+5
-1
@@ -654,7 +654,11 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
|||||||
guard let i = upcomingIndex() else { return }
|
guard let i = upcomingIndex() else { return }
|
||||||
let item = queue[i]
|
let item = queue[i]
|
||||||
nextTask = Task { @MainActor [weak self] in
|
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 }
|
guard let self, !Task.isCancelled else { return }
|
||||||
// The normal load path reports failures.
|
// The normal load path reports failures.
|
||||||
guard let (s, entry) = try? await self.openDetached(item.track, 0) else { return }
|
guard let (s, entry) = try? await self.openDetached(item.track, 0) else { return }
|
||||||
|
|||||||
Reference in new issue
Block a user