diff options
Diffstat (limited to 'player-android/lib/screens/video_player_screen.dart')
| -rw-r--r-- | player-android/lib/screens/video_player_screen.dart | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/player-android/lib/screens/video_player_screen.dart b/player-android/lib/screens/video_player_screen.dart index 311e51f..b3247a3 100644 --- a/player-android/lib/screens/video_player_screen.dart +++ b/player-android/lib/screens/video_player_screen.dart @@ -36,6 +36,7 @@ class VideoPlayerScreen extends ConsumerStatefulWidget { super.key, required this.mediaId, this.mediaUrl, + this.startPosition, }); /// The media item identifier extracted from the '/video/:mediaId' route path. @@ -46,6 +47,11 @@ class VideoPlayerScreen extends ConsumerStatefulWidget { /// base URL stays in a single place (Dependency Inversion Principle). final String? mediaUrl; + /// Optional start position in seconds, forwarded from the continue-watching + /// screen to resume at the saved position without an extra API round-trip. + /// When null, [PlayerApiClient.getMediaProgress] is called instead. + final double? startPosition; + @override ConsumerState<VideoPlayerScreen> createState() => _VideoPlayerScreenState(); } @@ -145,10 +151,13 @@ class _VideoPlayerScreenState extends ConsumerState<VideoPlayerScreen> { return; } - // Step 4: resume from the server-saved position (best-effort; ignore - // errors so a missing progress row never blocks playback). + // Step 4: resume from the saved position. + // Prefer [widget.startPosition] (forwarded by the continue-watching screen) + // to avoid a redundant API round-trip. Fall back to [getMediaProgress] so + // videos opened from other screens still resume correctly. try { - final savedSeconds = await client.getMediaProgress(mediaIdInt); + final savedSeconds = + widget.startPosition ?? await client.getMediaProgress(mediaIdInt); if (savedSeconds != null && savedSeconds > 0) { await videoController.seekTo( Duration(milliseconds: (savedSeconds * 1000).round()), |
