diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java index 2eafa388e3..4c258c748f 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java @@ -276,6 +276,7 @@ public class PlayerNotificationManager { private NotificationListener notificationListener; private MediaSessionCompat.Token mediaSessionToken; private boolean useNavigationActions; + private boolean usePlayPauseActions; private @Nullable String stopAction; private @Nullable PendingIntent stopPendingIntent; private long fastForwardMs; @@ -381,6 +382,7 @@ public class PlayerNotificationManager { setStopAction(ACTION_STOP); useNavigationActions = true; + usePlayPauseActions = true; ongoing = true; colorized = true; useChronometer = true; @@ -485,6 +487,18 @@ public class PlayerNotificationManager { } } + /** + * Sets whether the play and pause actions should be used. + * + * @param usePlayPauseActions Whether to use play and pause actions. + */ + public final void setUsePlayPauseActions(boolean usePlayPauseActions) { + if (this.usePlayPauseActions != usePlayPauseActions) { + this.usePlayPauseActions = usePlayPauseActions; + maybeUpdateNotification(); + } + } + /** * Sets the name of the action to be used as stop action to cancel the notification. If {@code * null} is passed the stop action is not displayed. @@ -878,10 +892,12 @@ public class PlayerNotificationManager { if (rewindMs > 0) { stringActions.add(ACTION_REWIND); } - if (player.getPlayWhenReady()) { - stringActions.add(ACTION_PAUSE); - } else if (!player.getPlayWhenReady()) { - stringActions.add(ACTION_PLAY); + if (usePlayPauseActions) { + if (player.getPlayWhenReady()) { + stringActions.add(ACTION_PAUSE); + } else { + stringActions.add(ACTION_PLAY); + } } if (fastForwardMs > 0) { stringActions.add(ACTION_FAST_FORWARD); @@ -908,6 +924,9 @@ public class PlayerNotificationManager { * @param player The player for which state to build a notification. */ protected int[] getActionIndicesForCompactView(Player player) { + if (!usePlayPauseActions) { + return new int[0]; + } int actionIndex = useNavigationActions ? 1 : 0; actionIndex += fastForwardMs > 0 ? 1 : 0; return new int[] {actionIndex};