Suppress stale player error after switching videos mid-retry

If the MPV backend was retrying a failed load and the user switched to
another video before retries exhausted, the eventual error was published
to the player UI even though that video was no longer active. Guard the
catch block with a loadingVideoID check so stale errors are dropped.
This commit is contained in:
Arkadiusz Fal
2026-05-10 01:02:18 +02:00
parent 4935fbdb83
commit 100e762d4b

View File

@@ -498,6 +498,16 @@ final class PlayerService {
LoggingService.shared.logPlayer("Playback cancelled: \(video.id.id)") LoggingService.shared.logPlayer("Playback cancelled: \(video.id.id)")
sleepPreventionService.allowSleep() sleepPreventionService.allowSleep()
} catch { } catch {
// If the user has already switched to a different video while this one was
// still loading/retrying, suppress the error it no longer applies to what
// is on screen. loadingVideoID is reassigned by every new play() call and
// cleared on success, so a mismatch means we are no longer the active load.
guard loadingVideoID == video.id else {
LoggingService.shared.logPlayer("Ignoring stale playback error for \(video.id.id) — user switched videos")
sleepPreventionService.allowSleep()
return
}
LoggingService.shared.logPlayerError("Playback failed: \(video.id.id)", error: error) LoggingService.shared.logPlayerError("Playback failed: \(video.id.id)", error: error)
sleepPreventionService.allowSleep() sleepPreventionService.allowSleep()
state.videoDetailsState = .error state.videoDetailsState = .error