diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java index 90b53c4a57..9f3897ec0c 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java @@ -16,6 +16,9 @@ package com.google.android.exoplayer2.ext.mediasession; import static androidx.media.utils.MediaConstants.PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_WINDOW; import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_PARAMETERS_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_STATE_CHANGED; @@ -912,16 +915,16 @@ public final class MediaSessionConnector { } private long buildPlaybackActions(Player player) { - boolean enableSeeking = false; - boolean enableRewind = false; - boolean enableFastForward = false; + boolean enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); + boolean enableRewind = + player.isCommandAvailable(COMMAND_SEEK_BACK) && controlDispatcher.isRewindEnabled(); + boolean enableFastForward = + player.isCommandAvailable(COMMAND_SEEK_FORWARD) && controlDispatcher.isFastForwardEnabled(); + boolean enableSetRating = false; boolean enableSetCaptioningEnabled = false; Timeline timeline = player.getCurrentTimeline(); if (!timeline.isEmpty() && !player.isPlayingAd()) { - enableSeeking = player.isCurrentWindowSeekable(); - enableRewind = enableSeeking && controlDispatcher.isRewindEnabled(); - enableFastForward = enableSeeking && controlDispatcher.isFastForwardEnabled(); enableSetRating = ratingCallback != null; enableSetCaptioningEnabled = captionCallback != null && captionCallback.hasCaptions(player); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java index f754368e98..4d10bb1d98 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java @@ -15,9 +15,11 @@ */ package com.google.android.exoplayer2.ui; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD; import static com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_WINDOW; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS; import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_STATE_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAY_WHEN_READY_CHANGED; @@ -869,21 +871,14 @@ public class PlayerControlView extends FrameLayout { boolean enableFastForward = false; boolean enableNext = false; if (player != null) { - Timeline timeline = player.getCurrentTimeline(); - if (!timeline.isEmpty() && !player.isPlayingAd()) { - boolean isSeekable = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); - timeline.getWindow(player.getCurrentWindowIndex(), window); - enableSeeking = isSeekable; - enablePrevious = - isSeekable - || !window.isLive() - || player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_WINDOW); - enableRewind = isSeekable && controlDispatcher.isRewindEnabled(); - enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled(); - enableNext = - (window.isLive() && window.isDynamic) - || player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_WINDOW); - } + enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); + enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS); + enableRewind = + player.isCommandAvailable(COMMAND_SEEK_BACK) && controlDispatcher.isRewindEnabled(); + enableFastForward = + player.isCommandAvailable(COMMAND_SEEK_FORWARD) + && controlDispatcher.isFastForwardEnabled(); + enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT); } updateButton(showPreviousButton, enablePrevious, previousButton); 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 5cb2d64113..49f88362c9 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 @@ -15,9 +15,10 @@ */ package com.google.android.exoplayer2.ui; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_WINDOW; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS; import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_MEDIA_METADATA_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_PARAMETERS_CHANGED; @@ -53,7 +54,6 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultControlDispatcher; import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.util.NotificationUtil; import com.google.android.exoplayer2.util.Util; import java.lang.annotation.Documented; @@ -677,7 +677,6 @@ public class PlayerNotificationManager { private final Map customActions; private final PendingIntent dismissPendingIntent; private final int instanceId; - private final Timeline.Window window; @Nullable private NotificationCompat.Builder builder; @Nullable private List builderActions; @@ -730,7 +729,6 @@ public class PlayerNotificationManager { this.smallIconResourceId = smallIconResourceId; this.groupKey = groupKey; controlDispatcher = new DefaultControlDispatcher(); - window = new Timeline.Window(); instanceId = instanceIdCounter++; // This fails the nullness checker because handleMessage() is 'called' while `this` is still // @UnderInitialization. No tasks are scheduled on mainHandler before the constructor completes, @@ -1291,24 +1289,12 @@ public class PlayerNotificationManager { * action name is ignored. */ protected List getActions(Player player) { - boolean enablePrevious = false; - boolean enableRewind = false; - boolean enableFastForward = false; - boolean enableNext = false; - Timeline timeline = player.getCurrentTimeline(); - if (!timeline.isEmpty() && !player.isPlayingAd()) { - boolean isSeekable = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); - timeline.getWindow(player.getCurrentWindowIndex(), window); - enablePrevious = - isSeekable - || !window.isLive() - || player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_WINDOW); - enableRewind = isSeekable && controlDispatcher.isRewindEnabled(); - enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled(); - enableNext = - (window.isLive() && window.isDynamic) - || player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_WINDOW); - } + boolean enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS); + boolean enableRewind = + player.isCommandAvailable(COMMAND_SEEK_BACK) && controlDispatcher.isRewindEnabled(); + boolean enableFastForward = + player.isCommandAvailable(COMMAND_SEEK_FORWARD) && controlDispatcher.isFastForwardEnabled(); + boolean enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT); List stringActions = new ArrayList<>(); if (usePreviousAction && enablePrevious) { diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index 777229d6fb..c368538cad 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -15,9 +15,11 @@ */ package com.google.android.exoplayer2.ui; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD; import static com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_WINDOW; -import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_WINDOW; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT; +import static com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS; import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_PARAMETERS_CHANGED; import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_STATE_CHANGED; @@ -1131,21 +1133,14 @@ public class StyledPlayerControlView extends FrameLayout { boolean enableFastForward = false; boolean enableNext = false; if (player != null) { - Timeline timeline = player.getCurrentTimeline(); - if (!timeline.isEmpty() && !player.isPlayingAd()) { - boolean isSeekable = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); - timeline.getWindow(player.getCurrentWindowIndex(), window); - enableSeeking = isSeekable; - enablePrevious = - isSeekable - || !window.isLive() - || player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_WINDOW); - enableRewind = isSeekable && controlDispatcher.isRewindEnabled(); - enableFastForward = isSeekable && controlDispatcher.isFastForwardEnabled(); - enableNext = - (window.isLive() && window.isDynamic) - || player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_WINDOW); - } + enableSeeking = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_WINDOW); + enablePrevious = player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS); + enableRewind = + player.isCommandAvailable(COMMAND_SEEK_BACK) && controlDispatcher.isRewindEnabled(); + enableFastForward = + player.isCommandAvailable(COMMAND_SEEK_FORWARD) + && controlDispatcher.isFastForwardEnabled(); + enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT); } if (enableRewind) {