Skip to content

Commit b75475c

Browse files
authored
Merge pull request #626 from BuginRug/feature/hideControlsTimer
Added customizable timer to hide controls
2 parents 8c27501 + 673fdd6 commit b75475c

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

example/lib/app/app.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class _ChewieDemoState extends State<ChewieDemo> {
133133
),
134134
),
135135

136+
hideControlsTimer: const Duration(seconds: 1),
137+
136138
// Try playing around with some of these other options:
137139

138140
// showControls: false,

lib/src/chewie_player.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class ChewieController extends ChangeNotifier {
280280
this.systemOverlaysAfterFullScreen = SystemUiOverlay.values,
281281
this.deviceOrientationsAfterFullScreen = DeviceOrientation.values,
282282
this.routePageBuilder,
283+
this.hideControlsTimer = defaultHideControlsTimer,
283284
}) : assert(
284285
playbackSpeeds.every((speed) => speed > 0),
285286
'The playbackSpeeds values must all be greater than 0',
@@ -317,6 +318,7 @@ class ChewieController extends ChangeNotifier {
317318
bool? allowMuting,
318319
bool? allowPlaybackSpeedChanging,
319320
bool? useRootNavigator,
321+
Duration? hideControlsTimer,
320322
List<double>? playbackSpeeds,
321323
List<SystemUiOverlay>? systemOverlaysOnEnterFullScreen,
322324
List<DeviceOrientation>? deviceOrientationsOnEnterFullScreen,
@@ -374,9 +376,12 @@ class ChewieController extends ChangeNotifier {
374376
deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ??
375377
this.deviceOrientationsAfterFullScreen,
376378
routePageBuilder: routePageBuilder ?? this.routePageBuilder,
379+
hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer,
377380
);
378381
}
379382

383+
static const defaultHideControlsTimer = Duration(seconds: 3);
384+
380385
/// If false, the options button in MaterialUI and MaterialDesktopUI
381386
/// won't be shown.
382387
final bool showOptions;
@@ -487,6 +492,9 @@ class ChewieController extends ChangeNotifier {
487492
/// Defines if push/pop navigations use the rootNavigator
488493
final bool useRootNavigator;
489494

495+
/// Defines the [Duration] before the video controls are hidden. By default, this is set to three seconds.
496+
final Duration hideControlsTimer;
497+
490498
/// Defines the set of allowed playback speeds user can change
491499
final List<double> playbackSpeeds;
492500

lib/src/cupertino/cupertino_controls.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,10 @@ class _CupertinoControlsState extends State<CupertinoControls>
759759
}
760760

761761
void _startHideTimer() {
762-
_hideTimer = Timer(const Duration(seconds: 3), () {
762+
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
763+
? ChewieController.defaultHideControlsTimer
764+
: chewieController.hideControlsTimer;
765+
_hideTimer = Timer(hideControlsTimer, () {
763766
setState(() {
764767
notifier.hideStuff = true;
765768
});

lib/src/material/material_controls.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ class _MaterialControlsState extends State<MaterialControls>
540540
}
541541

542542
void _startHideTimer() {
543-
_hideTimer = Timer(const Duration(seconds: 3), () {
543+
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
544+
? ChewieController.defaultHideControlsTimer
545+
: chewieController.hideControlsTimer;
546+
_hideTimer = Timer(hideControlsTimer, () {
544547
setState(() {
545548
notifier.hideStuff = true;
546549
});

lib/src/material/material_desktop_controls.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
520520
}
521521

522522
void _startHideTimer() {
523-
_hideTimer = Timer(const Duration(seconds: 3), () {
523+
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
524+
? ChewieController.defaultHideControlsTimer
525+
: chewieController.hideControlsTimer;
526+
_hideTimer = Timer(hideControlsTimer, () {
524527
setState(() {
525528
notifier.hideStuff = true;
526529
});

0 commit comments

Comments
 (0)