Skip to content

Add background tap to pause video feature #875

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 1 commit into from
Apr 2, 2025
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
6 changes: 6 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
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',
Expand Down Expand Up @@ -365,6 +366,7 @@
Animation<double>,
ChewieControllerProvider,
)? routePageBuilder,
bool? pauseOnBackgroundTap,
}) {
return ChewieController(
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
Expand Down Expand Up @@ -420,6 +422,7 @@
hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer,
progressIndicatorDelay:
progressIndicatorDelay ?? this.progressIndicatorDelay,
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap,

Check warning on line 425 in lib/src/chewie_player.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chewie_player.dart#L425

Added line #L425 was not covered by tests
);
}

Expand Down Expand Up @@ -584,6 +587,9 @@
/// 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<ChewieControllerProvider>()!;
Expand Down
10 changes: 9 additions & 1 deletion lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@

return GestureDetector(
onTap: _latestValue.isPlaying
? _cancelAndRestartTimer
? _chewieController?.pauseOnBackgroundTap ?? false
? () {
_playPause();

Check warning on line 359 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L357-L359

Added lines #L357 - L359 were not covered by tests

setState(() {
notifier.hideStuff = true;

Check warning on line 362 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L361-L362

Added lines #L361 - L362 were not covered by tests
});
}
: _cancelAndRestartTimer

Check warning on line 365 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L365

Added line #L365 was not covered by tests
: () {
_hideTimer?.cancel();

Expand Down
15 changes: 10 additions & 5 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,17 @@
return GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
if (_chewieController?.pauseOnBackgroundTap ?? false) {
_playPause();

Check warning on line 384 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L383-L384

Added lines #L383 - L384 were not covered by tests
_cancelAndRestartTimer();
} else {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;

Check warning on line 389 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L387-L389

Added lines #L387 - L389 were not covered by tests
});
} else {
_cancelAndRestartTimer();

Check warning on line 392 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L392

Added line #L392 was not covered by tests
}
}
} else {
_playPause();
Expand Down
20 changes: 14 additions & 6 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@
_cancelAndRestartTimer();
},
child: GestureDetector(
onTap: () => _cancelAndRestartTimer(),
onTap: () {
_playPause();
_cancelAndRestartTimer();

Check warning on line 111 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L109-L111

Added lines #L109 - L111 were not covered by tests
},
child: AbsorbPointer(
absorbing: notifier.hideStuff,
child: Stack(
Expand Down Expand Up @@ -365,12 +368,17 @@
return GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
if (_chewieController?.pauseOnBackgroundTap ?? false) {
_playPause();

Check warning on line 372 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L371-L372

Added lines #L371 - L372 were not covered by tests
_cancelAndRestartTimer();
} else {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;

Check warning on line 377 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L375-L377

Added lines #L375 - L377 were not covered by tests
});
} else {
_cancelAndRestartTimer();

Check warning on line 380 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L380

Added line #L380 was not covered by tests
}
}
} else {
_playPause();
Expand Down