Skip to content

Commit 72ef34e

Browse files
author
h.carnot
committed
feat: added support for apple and desktop version
1 parent a75b67c commit 72ef34e

File tree

4 files changed

+66
-15
lines changed

4 files changed

+66
-15
lines changed

lib/src/chewie_player.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class ChewieController extends ChangeNotifier {
519519
/// Defines a custom RoutePageBuilder for the fullscreen
520520
final ChewieRoutePageBuilder? routePageBuilder;
521521

522-
/// [Android] Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it.
522+
/// Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it.
523523
final Duration? progressIndicatorDelay;
524524

525525
static ChewieController of(BuildContext context) {

lib/src/cupertino/cupertino_controls.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
4747
bool _dragging = false;
4848
Duration? _subtitlesPosition;
4949
bool _subtitleOn = false;
50+
Timer? _bufferingDisplayTimer;
51+
bool _displayBufferingIndicator = false;
5052

5153
late VideoPlayerController controller;
5254

@@ -91,7 +93,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
9193
absorbing: notifier.hideStuff,
9294
child: Stack(
9395
children: [
94-
if (_latestValue.isBuffering)
96+
if (_displayBufferingIndicator)
9597
const Center(
9698
child: CircularProgressIndicator(),
9799
)
@@ -769,8 +771,32 @@ class _CupertinoControlsState extends State<CupertinoControls>
769771
});
770772
}
771773

774+
void _bufferingTimerTimeout() {
775+
_displayBufferingIndicator = true;
776+
if (mounted) {
777+
setState(() {});
778+
}
779+
}
780+
772781
void _updateState() {
773782
if (!mounted) return;
783+
784+
// display the progress bar indicator only after the buffering delay if it has been set
785+
if (chewieController.progressIndicatorDelay != null) {
786+
if (controller.value.isBuffering) {
787+
_bufferingDisplayTimer ??= Timer(
788+
chewieController.progressIndicatorDelay!,
789+
_bufferingTimerTimeout,
790+
);
791+
} else {
792+
_bufferingDisplayTimer?.cancel();
793+
_bufferingDisplayTimer = null;
794+
_displayBufferingIndicator = false;
795+
}
796+
} else {
797+
_displayBufferingIndicator = controller.value.isBuffering;
798+
}
799+
774800
setState(() {
775801
_latestValue = controller.value;
776802
_subtitlesPosition = controller.value.position;

lib/src/material/material_controls.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class _MaterialControlsState extends State<MaterialControls>
4040
Timer? _showAfterExpandCollapseTimer;
4141
bool _dragging = false;
4242
bool _displayTapped = false;
43+
Timer? _bufferingDisplayTimer;
44+
bool _displayBufferingIndicator = false;
4345

4446
final barHeight = 48.0 * 1.5;
4547
final marginSize = 5.0;
@@ -82,7 +84,7 @@ class _MaterialControlsState extends State<MaterialControls>
8284
absorbing: notifier.hideStuff,
8385
child: Stack(
8486
children: [
85-
if (displayLoading)
87+
if (_displayBufferingIndicator)
8688
const Center(
8789
child: CircularProgressIndicator(),
8890
)
@@ -550,11 +552,8 @@ class _MaterialControlsState extends State<MaterialControls>
550552
});
551553
}
552554

553-
Timer? timerInstance;
554-
bool displayLoading = false;
555-
556-
void handleTimeout() {
557-
displayLoading = true;
555+
void _bufferingTimerTimeout() {
556+
_displayBufferingIndicator = true;
558557
if (mounted) {
559558
setState(() {});
560559
}
@@ -566,17 +565,17 @@ class _MaterialControlsState extends State<MaterialControls>
566565
// display the progress bar indicator only after the buffering delay if it has been set
567566
if (chewieController.progressIndicatorDelay != null) {
568567
if (controller.value.isBuffering) {
569-
timerInstance ??= Timer(
568+
_bufferingDisplayTimer ??= Timer(
570569
chewieController.progressIndicatorDelay!,
571-
handleTimeout,
570+
_bufferingTimerTimeout,
572571
);
573572
} else {
574-
timerInstance?.cancel();
575-
timerInstance = null;
576-
displayLoading = false;
573+
_bufferingDisplayTimer?.cancel();
574+
_bufferingDisplayTimer = null;
575+
_displayBufferingIndicator = false;
577576
}
578577
} else {
579-
displayLoading = controller.value.isBuffering;
578+
_displayBufferingIndicator = controller.value.isBuffering;
580579
}
581580

582581
setState(() {

lib/src/material/material_desktop_controls.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
4141
Timer? _showAfterExpandCollapseTimer;
4242
bool _dragging = false;
4343
bool _displayTapped = false;
44+
Timer? _bufferingDisplayTimer;
45+
bool _displayBufferingIndicator = false;
4446

4547
final barHeight = 48.0 * 1.5;
4648
final marginSize = 5.0;
@@ -83,7 +85,7 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
8385
absorbing: notifier.hideStuff,
8486
child: Stack(
8587
children: [
86-
if (_latestValue.isBuffering)
88+
if (_displayBufferingIndicator)
8789
const Center(
8890
child: CircularProgressIndicator(),
8991
)
@@ -530,8 +532,32 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
530532
});
531533
}
532534

535+
void _bufferingTimerTimeout() {
536+
_displayBufferingIndicator = true;
537+
if (mounted) {
538+
setState(() {});
539+
}
540+
}
541+
533542
void _updateState() {
534543
if (!mounted) return;
544+
545+
// display the progress bar indicator only after the buffering delay if it has been set
546+
if (chewieController.progressIndicatorDelay != null) {
547+
if (controller.value.isBuffering) {
548+
_bufferingDisplayTimer ??= Timer(
549+
chewieController.progressIndicatorDelay!,
550+
_bufferingTimerTimeout,
551+
);
552+
} else {
553+
_bufferingDisplayTimer?.cancel();
554+
_bufferingDisplayTimer = null;
555+
_displayBufferingIndicator = false;
556+
}
557+
} else {
558+
_displayBufferingIndicator = controller.value.isBuffering;
559+
}
560+
535561
setState(() {
536562
_latestValue = controller.value;
537563
_subtitlesPosition = controller.value.position;

0 commit comments

Comments
 (0)