diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index ea75ce99c..5d76fdf6d 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -308,6 +308,7 @@ class ChewieController extends ChangeNotifier { this.progressIndicatorDelay, this.hideControlsTimer = defaultHideControlsTimer, this.controlsSafeAreaMinimum = EdgeInsets.zero, + this.pauseOnBackgroundTap = false, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -365,6 +366,7 @@ class ChewieController extends ChangeNotifier { Animation, ChewieControllerProvider, )? routePageBuilder, + bool? pauseOnBackgroundTap, }) { return ChewieController( draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar, @@ -420,6 +422,7 @@ class ChewieController extends ChangeNotifier { hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, progressIndicatorDelay: progressIndicatorDelay ?? this.progressIndicatorDelay, + pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap, ); } @@ -584,6 +587,9 @@ class ChewieController extends ChangeNotifier { /// Defaults to [EdgeInsets.zero]. final EdgeInsets controlsSafeAreaMinimum; + /// Defines if the player should pause when the background is tapped + final bool pauseOnBackgroundTap; + static ChewieController of(BuildContext context) { final chewieControllerProvider = context.dependOnInheritedWidgetOfExactType()!; diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index d3ae75d65..db7267836 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -354,7 +354,15 @@ class _CupertinoControlsState extends State return GestureDetector( onTap: _latestValue.isPlaying - ? _cancelAndRestartTimer + ? _chewieController?.pauseOnBackgroundTap ?? false + ? () { + _playPause(); + + setState(() { + notifier.hideStuff = true; + }); + } + : _cancelAndRestartTimer : () { _hideTimer?.cancel(); diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index f77fbcb58..2d813e05a 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -380,12 +380,17 @@ class _MaterialControlsState extends State return GestureDetector( onTap: () { if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { + if (_chewieController?.pauseOnBackgroundTap ?? false) { + _playPause(); _cancelAndRestartTimer(); + } else { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } } } else { _playPause(); diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 91d4afeaa..4b0ba0fe8 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -106,7 +106,10 @@ class _MaterialDesktopControlsState extends State _cancelAndRestartTimer(); }, child: GestureDetector( - onTap: () => _cancelAndRestartTimer(), + onTap: () { + _playPause(); + _cancelAndRestartTimer(); + }, child: AbsorbPointer( absorbing: notifier.hideStuff, child: Stack( @@ -365,12 +368,17 @@ class _MaterialDesktopControlsState extends State return GestureDetector( onTap: () { if (_latestValue.isPlaying) { - if (_displayTapped) { - setState(() { - notifier.hideStuff = true; - }); - } else { + if (_chewieController?.pauseOnBackgroundTap ?? false) { + _playPause(); _cancelAndRestartTimer(); + } else { + if (_displayTapped) { + setState(() { + notifier.hideStuff = true; + }); + } else { + _cancelAndRestartTimer(); + } } } else { _playPause();