diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 14ad71b3a3..ae18af495b 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -4,7 +4,10 @@ * Core Library: * Add `needsReconfiguration` API to the `MediaCodecAdapter` interface. - * Add `seekForward`, `seekBack` and `seekToPrevious` methods to `Player`. + * Add `getSeekForwardIncrement`, `seekForward`, `getSeekBackIncrement` + and `seekBack` methods to `Player`. + * Add `getMaxSeekToPreviousPosition` and `seekToPrevious` methods to + `Player`. * Make `Player` depend on the new `PlaybackException` class instead of `ExoPlaybackException`: * `Player.getPlayerError` now returns a `PlaybackException`. diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java index 0a94d67fb2..29f0578613 100644 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java +++ b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java @@ -458,6 +458,11 @@ public final class CastPlayer extends BasePlayer { return seekBackIncrementMs; } + @Override + public int getMaxSeekToPreviousPosition() { + return C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS; + } + @Override public void setPlaybackParameters(PlaybackParameters playbackParameters) { // Unsupported by the RemoteMediaClient API. Do nothing. diff --git a/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java b/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java index a50b1935c3..ab62fe8835 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java @@ -155,7 +155,7 @@ public abstract class BasePlayer implements Player { if (hasPrevious) { previous(); } - } else if (hasPrevious && getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS_MS) { + } else if (hasPrevious && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { previous(); } else { seekTo(/* positionMs= */ 0); diff --git a/library/common/src/main/java/com/google/android/exoplayer2/C.java b/library/common/src/main/java/com/google/android/exoplayer2/C.java index dbd940ed32..8782ab2b99 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/C.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/C.java @@ -651,6 +651,12 @@ public final class C { /** A default seek back increment, in milliseconds. */ public static final long DEFAULT_SEEK_BACK_INCREMENT_MS = 5000; + /** + * A default maximum position for which a seek to previous will seek to the previous window, in + * milliseconds. + */ + public static final int DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS = 3000; + /** "cenc" scheme type name as defined in ISO/IEC 23001-7:2016. */ @SuppressWarnings("ConstantField") public static final String CENC_TYPE_cenc = "cenc"; diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java index 0b593f6cb9..8f14246283 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java @@ -282,6 +282,11 @@ public class ForwardingPlayer implements Player { player.seekToPrevious(); } + @Override + public int getMaxSeekToPreviousPosition() { + return player.getMaxSeekToPreviousPosition(); + } + @Override public boolean hasNext() { return player.hasNext(); @@ -711,6 +716,11 @@ public class ForwardingPlayer implements Player { eventListener.onSeekBackIncrementChanged(seekBackIncrementMs); } + @Override + public void onMaxSeekToPreviousPositionChanged(int maxSeekToPreviousPositionMs) { + eventListener.onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs); + } + @Override public void onSeekProcessed() { eventListener.onSeekProcessed(); diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Player.java b/library/common/src/main/java/com/google/android/exoplayer2/Player.java index 1d41132c7c..a5707cde02 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/Player.java @@ -22,7 +22,6 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.TextureView; import androidx.annotation.IntDef; -import androidx.annotation.IntRange; import androidx.annotation.Nullable; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.audio.AudioListener; @@ -331,7 +330,7 @@ public interface Player { * * @param seekForwardIncrementMs The {@link #seekForward()} increment, in milliseconds. */ - default void onSeekForwardIncrementChanged(@IntRange(from = 1) long seekForwardIncrementMs) {} + default void onSeekForwardIncrementChanged(long seekForwardIncrementMs) {} /** * Called when the value of {@link #getSeekBackIncrement()} changes. @@ -341,7 +340,18 @@ public interface Player { * * @param seekBackIncrementMs The {@link #seekBack()} increment, in milliseconds. */ - default void onSeekBackIncrementChanged(@IntRange(from = 1) long seekBackIncrementMs) {} + default void onSeekBackIncrementChanged(long seekBackIncrementMs) {} + + /** + * Called when the value of {@link #getMaxSeekToPreviousPosition()} changes. + * + *
{@link #onEvents(Player, Events)} will also be called to report this event along with + * other events that happen in the same {@link Looper} message queue iteration. + * + * @param maxSeekToPreviousPositionMs The maximum position for which {@link #seekToPrevious()} + * seeks to the previous position, in milliseconds. + */ + default void onMaxSeekToPreviousPositionChanged(int maxSeekToPreviousPositionMs) {} /** * @deprecated Seeks are processed without delay. Listen to {@link @@ -884,9 +894,6 @@ public interface Player { default void onMetadata(Metadata metadata) {} } - /** The maximum position for which {@link #seekToPrevious()} seeks to the previous window. */ - int MAX_POSITION_FOR_SEEK_TO_PREVIOUS_MS = 3000; - /** * Playback state. One of {@link #STATE_IDLE}, {@link #STATE_BUFFERING}, {@link #STATE_READY} or * {@link #STATE_ENDED}. @@ -1100,7 +1107,8 @@ public interface Player { EVENT_MEDIA_METADATA_CHANGED, EVENT_PLAYLIST_METADATA_CHANGED, EVENT_SEEK_FORWARD_INCREMENT_CHANGED, - EVENT_SEEK_BACK_INCREMENT_CHANGED + EVENT_SEEK_BACK_INCREMENT_CHANGED, + EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED }) @interface EventFlags {} /** {@link #getCurrentTimeline()} changed. */ @@ -1144,6 +1152,8 @@ public interface Player { int EVENT_SEEK_FORWARD_INCREMENT_CHANGED = 17; /** {@link #getSeekBackIncrement()} changed. */ int EVENT_SEEK_BACK_INCREMENT_CHANGED = 18; + /** {@link #getMaxSeekToPreviousPosition()} changed. */ + int EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED = 19; /** * Commands that can be executed on a {@code Player}. One of {@link #COMMAND_PLAY_PAUSE}, {@link @@ -1656,6 +1666,15 @@ public interface Player { */ void previous(); + /** + * Returns the maximum position for which {@link #seekToPrevious()} seeks to the previous window, + * in milliseconds. + * + * @return The maximum seek to previous position, in milliseconds. + * @see Listener#onMaxSeekToPreviousPositionChanged(int) + */ + int getMaxSeekToPreviousPosition(); + /** * Seeks to an earlier position in the current or previous window (if available). More precisely: * @@ -1670,8 +1689,7 @@ public interface Player { * *