From dbb3e14c50ad02f5089a148fe68ec77cfa4f8a29 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Fri, 3 Apr 2026 17:50:36 +0200 Subject: [PATCH] fix: skip offline video when different version requested --- lib/services/playback_initialization_service.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/services/playback_initialization_service.dart b/lib/services/playback_initialization_service.dart index 8de2e92e..346eb031 100644 --- a/lib/services/playback_initialization_service.dart +++ b/lib/services/playback_initialization_service.dart @@ -27,7 +27,7 @@ class PlaybackInitializationService { /// /// Returns the local file path if the video is downloaded and completed. /// Returns null if not available offline or database is not provided. - Future getOfflineVideoPath(String serverId, String ratingKey) async { + Future getOfflineVideoPath(String serverId, String ratingKey, {int mediaIndex = 0}) async { if (database == null) { return null; } @@ -44,6 +44,13 @@ class PlaybackInitializationService { return null; } + // Skip offline file if a different version was requested + if (downloadedItem.mediaIndex != mediaIndex) { + appLogger.d('[VersionTrace] Offline video is version ${downloadedItem.mediaIndex}, ' + 'but requested version $mediaIndex — skipping offline'); + return null; + } + // Return null if no video file path if (downloadedItem.videoFilePath == null) { return null; @@ -87,7 +94,7 @@ class PlaybackInitializationService { // Check for offline content first if preferOffline is enabled String? offlineVideoPath; if (preferOffline && database != null) { - offlineVideoPath = await getOfflineVideoPath(client.serverId, metadata.ratingKey); + offlineVideoPath = await getOfflineVideoPath(client.serverId, metadata.ratingKey, mediaIndex: selectedMediaIndex); } // If offline video is available, use it