From 049de97a0b64b542f851e5090ca1bc35dd069ea3 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Wed, 10 Dec 2025 12:07:49 +0100 Subject: [PATCH] Fix: Resume playback retry logic + better debug logging - Added _seekToResume() method with retry logic (max 10 attempts) - Seek now waits until player is playing AND has duration loaded - Added debug logging for resume position checks - 500ms retry interval with 1.5s initial delay --- .../iptv/screens/native_player_screen.dart | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/mobile/features/iptv/screens/native_player_screen.dart b/lib/mobile/features/iptv/screens/native_player_screen.dart index d9c8384..8cd4f6d 100644 --- a/lib/mobile/features/iptv/screens/native_player_screen.dart +++ b/lib/mobile/features/iptv/screens/native_player_screen.dart @@ -290,6 +290,23 @@ class _NativePlayerScreenState extends ConsumerState { ); } + /// Seek to resume position with retry logic + void _seekToResume(int positionSeconds, [int attempt = 0]) { + if (!mounted || attempt >= 10) return; + + Future.delayed(Duration(milliseconds: attempt == 0 ? 1500 : 500), () { + if (!mounted) return; + + if (_isPlaying && _duration.inSeconds > 0) { + debugPrint('MediaKitPlayer: Seeking to resume position ${positionSeconds}s (attempt $attempt)'); + _player.seek(Duration(seconds: positionSeconds)); + } else { + debugPrint('MediaKitPlayer: Player not ready, retrying resume seek (attempt $attempt)'); + _seekToResume(positionSeconds, attempt + 1); + } + }); + } + /// Attempt to reconnect a live stream that stopped void _attemptReconnect() { if (!mounted) return; @@ -441,14 +458,9 @@ class _NativePlayerScreenState extends ConsumerState { // Resume from saved position (VOD/Series only) if (widget.streamType != StreamType.live) { final resumePos = ref.read(mobileWatchHistoryProvider).getResumePosition(_contentId); + debugPrint('MediaKitPlayer: Resume check - contentId: $_contentId, resumePos: $resumePos'); if (resumePos > 30) { - // Wait for player to stabilize, then seek - Future.delayed(const Duration(milliseconds: 1500), () { - if (mounted && _isPlaying) { - debugPrint('MediaKitPlayer: Resuming from ${resumePos}s'); - _player.seek(Duration(seconds: resumePos)); - } - }); + _seekToResume(resumePos); } } } catch (e) {