Skip to content

Added customizable timer to hide controls #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class _ChewieDemoState extends State<ChewieDemo> {
),
),

hideControlsTimer: const Duration(seconds: 1),

// Try playing around with some of these other options:

// showControls: false,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -317,6 +318,7 @@ class ChewieController extends ChangeNotifier {
bool? allowMuting,
bool? allowPlaybackSpeedChanging,
bool? useRootNavigator,
Duration? hideControlsTimer,
List<double>? playbackSpeeds,
List<SystemUiOverlay>? systemOverlaysOnEnterFullScreen,
List<DeviceOrientation>? deviceOrientationsOnEnterFullScreen,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<double> playbackSpeeds;

Expand Down
5 changes: 4 additions & 1 deletion lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,10 @@ class _CupertinoControlsState extends State<CupertinoControls>
}

void _startHideTimer() {
_hideTimer = Timer(const Duration(seconds: 3), () {
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
? ChewieController.defaultHideControlsTimer
: chewieController.hideControlsTimer;
_hideTimer = Timer(hideControlsTimer, () {
setState(() {
notifier.hideStuff = true;
});
Expand Down
5 changes: 4 additions & 1 deletion lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ class _MaterialControlsState extends State<MaterialControls>
}

void _startHideTimer() {
_hideTimer = Timer(const Duration(seconds: 3), () {
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
? ChewieController.defaultHideControlsTimer
: chewieController.hideControlsTimer;
_hideTimer = Timer(hideControlsTimer, () {
setState(() {
notifier.hideStuff = true;
});
Expand Down
5 changes: 4 additions & 1 deletion lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
}

void _startHideTimer() {
_hideTimer = Timer(const Duration(seconds: 3), () {
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
? ChewieController.defaultHideControlsTimer
: chewieController.hideControlsTimer;
_hideTimer = Timer(hideControlsTimer, () {
setState(() {
notifier.hideStuff = true;
});
Expand Down