Add buffering spinner to video player

Co-authored-by: Doezer <11655673+Doezer@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-14 07:57:37 +01:00
committed by Doezer
co-authored by Doezer
parent 7dbe5db11c
commit ed7c47b3db
+29
View File
@@ -61,12 +61,14 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> {
StreamSubscription<bool>? _completedSubscription;
StreamSubscription<Duration>? _positionSubscription;
StreamSubscription<dynamic>? _mediaControlSubscription;
StreamSubscription<bool>? _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<VideoPlayerScreen> {
_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<VideoPlayerScreen> {
_errorSubscription?.cancel();
_positionSubscription?.cancel();
_mediaControlSubscription?.cancel();
_bufferingSubscription?.cancel();
// Clear OS media controls completely
OsMediaControls.clear();
@@ -1504,6 +1516,23 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> {
),
),
),
// 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,
),
),
),
),
],
),
),