diff --git a/lib/screens/video_player_screen.dart b/lib/screens/video_player_screen.dart index 7d5a5826..a51de8c1 100644 --- a/lib/screens/video_player_screen.dart +++ b/lib/screens/video_player_screen.dart @@ -61,12 +61,14 @@ class VideoPlayerScreenState extends State { StreamSubscription? _completedSubscription; StreamSubscription? _positionSubscription; StreamSubscription? _mediaControlSubscription; + StreamSubscription? _bufferingSubscription; bool _isReplacingWithVideo = false; // Flag to skip orientation restoration during video-to-video navigation // BoxFit mode state: 0=contain (letterbox), 1=cover (fill screen), 2=fill (stretch) int _boxFitMode = 0; bool _isPinching = false; // Track if a pinch gesture is occurring + bool _isBuffering = false; // Track if video is currently buffering @override void initState() { @@ -222,6 +224,15 @@ class VideoPlayerScreenState extends State { _updateMediaControlsPosition(); }); + // Listen to buffering state + _bufferingSubscription = player!.stream.buffering.listen((isBuffering) { + if (mounted) { + setState(() { + _isBuffering = isBuffering; + }); + } + }); + // Initialize OS media controls _initializeMediaControls(); @@ -475,6 +486,7 @@ class VideoPlayerScreenState extends State { _errorSubscription?.cancel(); _positionSubscription?.cancel(); _mediaControlSubscription?.cancel(); + _bufferingSubscription?.cancel(); // Clear OS media controls completely OsMediaControls.clear(); @@ -1504,6 +1516,23 @@ class VideoPlayerScreenState extends State { ), ), ), + // Buffering indicator + if (_isBuffering) + Positioned.fill( + child: Center( + child: Container( + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: Colors.black.withValues(alpha: 0.5), + shape: BoxShape.circle, + ), + child: const CircularProgressIndicator( + color: Colors.white, + strokeWidth: 3, + ), + ), + ), + ), ], ), ),