diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 5ebe0620f..17b5f80af 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -307,6 +307,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', @@ -363,6 +364,7 @@ class ChewieController extends ChangeNotifier { Animation, ChewieControllerProvider, )? routePageBuilder, + bool? pauseOnBackgroundTap, }) { return ChewieController( draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar, @@ -417,6 +419,7 @@ class ChewieController extends ChangeNotifier { hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, progressIndicatorDelay: progressIndicatorDelay ?? this.progressIndicatorDelay, + pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap, ); } @@ -575,6 +578,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 ea0bf4d80..44e3323b2 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 9b20f0722..2d0de933d 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -374,12 +374,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 1b8fba8e2..827ccc6ed 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -336,12 +336,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();