diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 84970d9af..38840241b 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -133,6 +133,8 @@ class _ChewieDemoState extends State { ), ), + hideControlsTimer: const Duration(seconds: 1), + // Try playing around with some of these other options: // showControls: false, diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index bffb4d2e9..71eae87f1 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -280,6 +280,7 @@ class ChewieController extends ChangeNotifier { this.systemOverlaysAfterFullScreen = SystemUiOverlay.values, this.deviceOrientationsAfterFullScreen = DeviceOrientation.values, this.routePageBuilder, + this.hideControlsTimer = defaultHideControlsTimer, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -317,6 +318,7 @@ class ChewieController extends ChangeNotifier { bool? allowMuting, bool? allowPlaybackSpeedChanging, bool? useRootNavigator, + Duration? hideControlsTimer, List? playbackSpeeds, List? systemOverlaysOnEnterFullScreen, List? deviceOrientationsOnEnterFullScreen, @@ -374,9 +376,12 @@ class ChewieController extends ChangeNotifier { deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ?? this.deviceOrientationsAfterFullScreen, routePageBuilder: routePageBuilder ?? this.routePageBuilder, + hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, ); } + static const defaultHideControlsTimer = Duration(seconds: 3); + /// If false, the options button in MaterialUI and MaterialDesktopUI /// won't be shown. final bool showOptions; @@ -487,6 +492,9 @@ class ChewieController extends ChangeNotifier { /// Defines if push/pop navigations use the rootNavigator final bool useRootNavigator; + /// Defines the [Duration] before the video controls are hidden. By default, this is set to three seconds. + final Duration hideControlsTimer; + /// Defines the set of allowed playback speeds user can change final List playbackSpeeds; diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index bd42dfab0..a4e304ce8 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -759,7 +759,10 @@ class _CupertinoControlsState extends State } void _startHideTimer() { - _hideTimer = Timer(const Duration(seconds: 3), () { + final hideControlsTimer = chewieController.hideControlsTimer.isNegative + ? ChewieController.defaultHideControlsTimer + : chewieController.hideControlsTimer; + _hideTimer = Timer(hideControlsTimer, () { setState(() { notifier.hideStuff = true; }); diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 3f94f57a0..4c409e4ca 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -540,7 +540,10 @@ class _MaterialControlsState extends State } void _startHideTimer() { - _hideTimer = Timer(const Duration(seconds: 3), () { + final hideControlsTimer = chewieController.hideControlsTimer.isNegative + ? ChewieController.defaultHideControlsTimer + : chewieController.hideControlsTimer; + _hideTimer = Timer(hideControlsTimer, () { setState(() { notifier.hideStuff = true; }); diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index b56ab1357..2baa7cb22 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -520,7 +520,10 @@ class _MaterialDesktopControlsState extends State } void _startHideTimer() { - _hideTimer = Timer(const Duration(seconds: 3), () { + final hideControlsTimer = chewieController.hideControlsTimer.isNegative + ? ChewieController.defaultHideControlsTimer + : chewieController.hideControlsTimer; + _hideTimer = Timer(hideControlsTimer, () { setState(() { notifier.hideStuff = true; });