diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b2d6d800ef..9c2bbcc85b 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -8,6 +8,9 @@ `seekForward` methods to `Player`. * Add `getMaxSeekToPreviousPosition`, `seekToPrevious` and `seekToNext` methods to `Player`. + * Rename `Player` methods `hasPrevious`, `previous`, `hasNext` and `next` + to `hasPreviousWindow`, `seekToPreviousWindow`, `hasNextWindow` and + `seekToNextWindow`, respectively. * Rename `Player` commands `COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM`, `COMMAND_SEEK_TO_NEXT_MEDIA_ITEM`, `COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM`, `COMMAND_SEEK_TO_MEDIA_ITEM` and diff --git a/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java b/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java index 759f411141..a5cbcdb374 100644 --- a/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java +++ b/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java @@ -480,11 +480,11 @@ import java.util.List; } public boolean canSkipToPreviousPlaylistItem() { - return player.hasPrevious(); + return player.hasPreviousWindow(); } public boolean canSkipToNextPlaylistItem() { - return player.hasNext(); + return player.hasNextWindow(); } public boolean hasError() { 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 63e563997e..c2d1c7acfc 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 @@ -131,13 +131,25 @@ public abstract class BasePlayer implements Player { seekToOffset(getSeekForwardIncrement()); } + @Deprecated @Override public final boolean hasPrevious() { - return getPreviousWindowIndex() != C.INDEX_UNSET; + return hasPreviousWindow(); } + @Override + public final boolean hasPreviousWindow() { + return getPreviousWindowIndex() != C.INDEX_UNSET; + } + + @Deprecated @Override public final void previous() { + seekToPreviousWindow(); + } + + @Override + public final void seekToPreviousWindow() { int previousWindowIndex = getPreviousWindowIndex(); if (previousWindowIndex != C.INDEX_UNSET) { seekToDefaultPosition(previousWindowIndex); @@ -150,25 +162,37 @@ public abstract class BasePlayer implements Player { if (timeline.isEmpty() || isPlayingAd()) { return; } - boolean hasPrevious = hasPrevious(); + boolean hasPreviousWindow = hasPreviousWindow(); if (isCurrentWindowLive() && !isCurrentWindowSeekable()) { - if (hasPrevious) { - previous(); + if (hasPreviousWindow) { + seekToPreviousWindow(); } - } else if (hasPrevious && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { - previous(); + } else if (hasPreviousWindow && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { + seekToPreviousWindow(); } else { seekTo(/* positionMs= */ 0); } } + @Deprecated @Override public final boolean hasNext() { - return getNextWindowIndex() != C.INDEX_UNSET; + return hasNextWindow(); } + @Override + public final boolean hasNextWindow() { + return getNextWindowIndex() != C.INDEX_UNSET; + } + + @Deprecated @Override public final void next() { + seekToNextWindow(); + } + + @Override + public final void seekToNextWindow() { int nextWindowIndex = getNextWindowIndex(); if (nextWindowIndex != C.INDEX_UNSET) { seekToDefaultPosition(nextWindowIndex); @@ -181,8 +205,8 @@ public abstract class BasePlayer implements Player { if (timeline.isEmpty() || isPlayingAd()) { return; } - if (hasNext()) { - next(); + if (hasNextWindow()) { + seekToNextWindow(); } else if (isCurrentWindowLive() && isCurrentWindowDynamic()) { seekToDefaultPosition(); } @@ -295,17 +319,17 @@ public abstract class BasePlayer implements Player { .addAll(permanentAvailableCommands) .addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd()) .addIf(COMMAND_SEEK_IN_CURRENT_WINDOW, isCurrentWindowSeekable() && !isPlayingAd()) - .addIf(COMMAND_SEEK_TO_PREVIOUS_WINDOW, hasPrevious() && !isPlayingAd()) + .addIf(COMMAND_SEEK_TO_PREVIOUS_WINDOW, hasPreviousWindow() && !isPlayingAd()) .addIf( COMMAND_SEEK_TO_PREVIOUS, !getCurrentTimeline().isEmpty() - && (hasPrevious() || !isCurrentWindowLive() || isCurrentWindowSeekable()) + && (hasPreviousWindow() || !isCurrentWindowLive() || isCurrentWindowSeekable()) && !isPlayingAd()) - .addIf(COMMAND_SEEK_TO_NEXT_WINDOW, hasNext() && !isPlayingAd()) + .addIf(COMMAND_SEEK_TO_NEXT_WINDOW, hasNextWindow() && !isPlayingAd()) .addIf( COMMAND_SEEK_TO_NEXT, !getCurrentTimeline().isEmpty() - && (hasNext() || (isCurrentWindowLive() && isCurrentWindowDynamic())) + && (hasNextWindow() || (isCurrentWindowLive() && isCurrentWindowDynamic())) && !isPlayingAd()) .addIf(COMMAND_SEEK_TO_WINDOW, !isPlayingAd()) .addIf(COMMAND_SEEK_BACK, isCurrentWindowSeekable() && !isPlayingAd()) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ControlDispatcher.java b/library/common/src/main/java/com/google/android/exoplayer2/ControlDispatcher.java index 4e9b20acf3..02eb54c756 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ControlDispatcher.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ControlDispatcher.java @@ -55,7 +55,7 @@ public interface ControlDispatcher { boolean dispatchSeekTo(Player player, int windowIndex, long positionMs); /** - * Dispatches a {@link Player#previous()} operation. + * Dispatches a {@link Player#seekToPreviousWindow()} operation. * * @param player The {@link Player} to which the operation should be dispatched. * @return True if the operation was dispatched. False if suppressed. @@ -63,7 +63,7 @@ public interface ControlDispatcher { boolean dispatchPrevious(Player player); /** - * Dispatches a {@link Player#next()} operation. + * Dispatches a {@link Player#seekToNextWindow()} operation. * * @param player The {@link Player} to which the operation should be dispatched. * @return True if the operation was dispatched. False if suppressed. diff --git a/library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java b/library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java index a3f64892bd..ace1135052 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java @@ -75,10 +75,10 @@ public class DefaultControlDispatcher implements ControlDispatcher { } boolean isUnseekableLiveStream = player.isCurrentWindowLive() && !player.isCurrentWindowSeekable(); - if (player.hasPrevious() + if (player.hasPreviousWindow() && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS || isUnseekableLiveStream)) { - player.previous(); + player.seekToPreviousWindow(); } else if (!isUnseekableLiveStream) { player.seekTo(/* positionMs= */ 0); } @@ -91,8 +91,8 @@ public class DefaultControlDispatcher implements ControlDispatcher { if (timeline.isEmpty() || player.isPlayingAd()) { return true; } - if (player.hasNext()) { - player.next(); + if (player.hasNextWindow()) { + player.seekToNextWindow(); } else if (player.isCurrentWindowLive() && player.isCurrentWindowDynamic()) { player.seekToDefaultPosition(); } 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 770ac01b40..a2ff3c3aa4 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 @@ -267,16 +267,28 @@ public class ForwardingPlayer implements Player { player.seekForward(); } + @Deprecated @Override public boolean hasPrevious() { return player.hasPrevious(); } + @Override + public boolean hasPreviousWindow() { + return player.hasPreviousWindow(); + } + + @Deprecated @Override public void previous() { player.previous(); } + @Override + public void seekToPreviousWindow() { + player.seekToPreviousWindow(); + } + @Override public void seekToPrevious() { player.seekToPrevious(); @@ -287,16 +299,28 @@ public class ForwardingPlayer implements Player { return player.getMaxSeekToPreviousPosition(); } + @Deprecated @Override public boolean hasNext() { return player.hasNext(); } + @Override + public boolean hasNextWindow() { + return player.hasNextWindow(); + } + + @Deprecated @Override public void next() { player.next(); } + @Override + public void seekToNextWindow() { + player.seekToNextWindow(); + } + @Override public void seekToNext() { player.seekToNext(); 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 8bf858aab6..795a589afb 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 @@ -1542,9 +1542,9 @@ public interface Player { * *

This method does not execute the command. * - *

Executing a command that is not available (for example, calling {@link #next()} if {@link - * #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor generate a - * {@link #getPlayerError()} player error}. + *

Executing a command that is not available (for example, calling {@link #seekToNextWindow()} + * if {@link #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor + * generate a {@link #getPlayerError()} player error}. * *

{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are * unavailable if there is no such {@link MediaItem}. @@ -1562,9 +1562,9 @@ public interface Player { * Listener#onAvailableCommandsChanged(Commands)} to get an update when the available commands * change. * - *

Executing a command that is not available (for example, calling {@link #next()} if {@link - * #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor generate a - * {@link #getPlayerError()} player error}. + *

Executing a command that is not available (for example, calling {@link #seekToNextWindow()} + * if {@link #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor + * generate a {@link #getPlayerError()} player error}. * *

{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are * unavailable if there is no such {@link MediaItem}. @@ -1750,6 +1750,10 @@ public interface Player { /** Seeks forward in the current window by {@link #getSeekForwardIncrement()} milliseconds. */ void seekForward(); + /** @deprecated Use {@link #hasPreviousWindow()} instead. */ + @Deprecated + boolean hasPrevious(); + /** * Returns whether a previous window exists, which may depend on the current repeat mode and * whether shuffle mode is enabled. @@ -1758,18 +1762,22 @@ public interface Player { * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. */ - boolean hasPrevious(); + boolean hasPreviousWindow(); + + /** @deprecated Use {@link #seekToPreviousWindow()} instead. */ + @Deprecated + void previous(); /** * Seeks to the default position of the previous window, which may depend on the current repeat - * mode and whether shuffle mode is enabled. Does nothing if {@link #hasPrevious()} is {@code - * false}. + * mode and whether shuffle mode is enabled. Does nothing if {@link #hasPreviousWindow()} is + * {@code false}. * *

Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. */ - void previous(); + void seekToPreviousWindow(); /** * Returns the maximum position for which {@link #seekToPrevious()} seeks to the previous window, @@ -1788,11 +1796,11 @@ public interface Player { *

  • Otherwise, if the current window is {@link #isCurrentWindowLive() live} and {@link * #isCurrentWindowSeekable() unseekable}, then: * - *
  • Otherwise, if {@link #hasPrevious() a previous window exists} and the {@link + *
  • Otherwise, if {@link #hasPreviousWindow() a previous window exists} and the {@link * #getCurrentPosition() current position} is less than {@link * #getMaxSeekToPreviousPosition()}, seeks to the default position of the previous window. *
  • Otherwise, seeks to 0 in the current window. @@ -1800,6 +1808,10 @@ public interface Player { */ void seekToPrevious(); + /** @deprecated Use {@link #hasNextWindow()} instead. */ + @Deprecated + boolean hasNext(); + /** * Returns whether a next window exists, which may depend on the current repeat mode and whether * shuffle mode is enabled. @@ -1808,25 +1820,29 @@ public interface Player { * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. */ - boolean hasNext(); + boolean hasNextWindow(); + + /** @deprecated Use {@link #seekToNextWindow()} instead. */ + @Deprecated + void next(); /** * Seeks to the default position of the next window, which may depend on the current repeat mode - * and whether shuffle mode is enabled. Does nothing if {@link #hasNext()} is {@code false}. + * and whether shuffle mode is enabled. Does nothing if {@link #hasNextWindow()} is {@code false}. * *

    Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * details. */ - void next(); + void seekToNextWindow(); /** * Seeks to a later position in the current or next window (if available). More precisely: * *