From 100e762d4bf1a3afeeca0b436a5585947c5e8fd2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 10 May 2026 01:02:18 +0200 Subject: [PATCH] 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. --- Yattee/Services/Player/PlayerService.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Yattee/Services/Player/PlayerService.swift b/Yattee/Services/Player/PlayerService.swift index 14e62d01..a6e84aa9 100644 --- a/Yattee/Services/Player/PlayerService.swift +++ b/Yattee/Services/Player/PlayerService.swift @@ -498,6 +498,16 @@ final class PlayerService { LoggingService.shared.logPlayer("Playback cancelled: \(video.id.id)") sleepPreventionService.allowSleep() } 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) sleepPreventionService.allowSleep() state.videoDetailsState = .error