Commit ae31ebb1 by kimvde Committed by Oliver Woodman

Rename previous/next to seekToPrevious/NextWindow in Player

Also rename hasPrevious/Next to hasPrevious/NextWindow for consistency.

This makes it clearer what the difference between
seekToPrevious/NextWindow and seekToPrevious/Next is.

PiperOrigin-RevId: 384643373
parent 36705414
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
`seekForward` methods to `Player`. `seekForward` methods to `Player`.
* Add `getMaxSeekToPreviousPosition`, `seekToPrevious` and `seekToNext` * Add `getMaxSeekToPreviousPosition`, `seekToPrevious` and `seekToNext`
methods to `Player`. 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`, * Rename `Player` commands `COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM`,
`COMMAND_SEEK_TO_NEXT_MEDIA_ITEM`, `COMMAND_SEEK_TO_NEXT_MEDIA_ITEM`,
`COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM`, `COMMAND_SEEK_TO_MEDIA_ITEM` and `COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM`, `COMMAND_SEEK_TO_MEDIA_ITEM` and
......
...@@ -480,11 +480,11 @@ import java.util.List; ...@@ -480,11 +480,11 @@ import java.util.List;
} }
public boolean canSkipToPreviousPlaylistItem() { public boolean canSkipToPreviousPlaylistItem() {
return player.hasPrevious(); return player.hasPreviousWindow();
} }
public boolean canSkipToNextPlaylistItem() { public boolean canSkipToNextPlaylistItem() {
return player.hasNext(); return player.hasNextWindow();
} }
public boolean hasError() { public boolean hasError() {
......
...@@ -131,13 +131,25 @@ public abstract class BasePlayer implements Player { ...@@ -131,13 +131,25 @@ public abstract class BasePlayer implements Player {
seekToOffset(getSeekForwardIncrement()); seekToOffset(getSeekForwardIncrement());
} }
@Deprecated
@Override @Override
public final boolean hasPrevious() { public final boolean hasPrevious() {
return hasPreviousWindow();
}
@Override
public final boolean hasPreviousWindow() {
return getPreviousWindowIndex() != C.INDEX_UNSET; return getPreviousWindowIndex() != C.INDEX_UNSET;
} }
@Deprecated
@Override @Override
public final void previous() { public final void previous() {
seekToPreviousWindow();
}
@Override
public final void seekToPreviousWindow() {
int previousWindowIndex = getPreviousWindowIndex(); int previousWindowIndex = getPreviousWindowIndex();
if (previousWindowIndex != C.INDEX_UNSET) { if (previousWindowIndex != C.INDEX_UNSET) {
seekToDefaultPosition(previousWindowIndex); seekToDefaultPosition(previousWindowIndex);
...@@ -150,25 +162,37 @@ public abstract class BasePlayer implements Player { ...@@ -150,25 +162,37 @@ public abstract class BasePlayer implements Player {
if (timeline.isEmpty() || isPlayingAd()) { if (timeline.isEmpty() || isPlayingAd()) {
return; return;
} }
boolean hasPrevious = hasPrevious(); boolean hasPreviousWindow = hasPreviousWindow();
if (isCurrentWindowLive() && !isCurrentWindowSeekable()) { if (isCurrentWindowLive() && !isCurrentWindowSeekable()) {
if (hasPrevious) { if (hasPreviousWindow) {
previous(); seekToPreviousWindow();
} }
} else if (hasPrevious && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { } else if (hasPreviousWindow && getCurrentPosition() <= getMaxSeekToPreviousPosition()) {
previous(); seekToPreviousWindow();
} else { } else {
seekTo(/* positionMs= */ 0); seekTo(/* positionMs= */ 0);
} }
} }
@Deprecated
@Override @Override
public final boolean hasNext() { public final boolean hasNext() {
return hasNextWindow();
}
@Override
public final boolean hasNextWindow() {
return getNextWindowIndex() != C.INDEX_UNSET; return getNextWindowIndex() != C.INDEX_UNSET;
} }
@Deprecated
@Override @Override
public final void next() { public final void next() {
seekToNextWindow();
}
@Override
public final void seekToNextWindow() {
int nextWindowIndex = getNextWindowIndex(); int nextWindowIndex = getNextWindowIndex();
if (nextWindowIndex != C.INDEX_UNSET) { if (nextWindowIndex != C.INDEX_UNSET) {
seekToDefaultPosition(nextWindowIndex); seekToDefaultPosition(nextWindowIndex);
...@@ -181,8 +205,8 @@ public abstract class BasePlayer implements Player { ...@@ -181,8 +205,8 @@ public abstract class BasePlayer implements Player {
if (timeline.isEmpty() || isPlayingAd()) { if (timeline.isEmpty() || isPlayingAd()) {
return; return;
} }
if (hasNext()) { if (hasNextWindow()) {
next(); seekToNextWindow();
} else if (isCurrentWindowLive() && isCurrentWindowDynamic()) { } else if (isCurrentWindowLive() && isCurrentWindowDynamic()) {
seekToDefaultPosition(); seekToDefaultPosition();
} }
...@@ -295,17 +319,17 @@ public abstract class BasePlayer implements Player { ...@@ -295,17 +319,17 @@ public abstract class BasePlayer implements Player {
.addAll(permanentAvailableCommands) .addAll(permanentAvailableCommands)
.addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd()) .addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd())
.addIf(COMMAND_SEEK_IN_CURRENT_WINDOW, isCurrentWindowSeekable() && !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( .addIf(
COMMAND_SEEK_TO_PREVIOUS, COMMAND_SEEK_TO_PREVIOUS,
!getCurrentTimeline().isEmpty() !getCurrentTimeline().isEmpty()
&& (hasPrevious() || !isCurrentWindowLive() || isCurrentWindowSeekable()) && (hasPreviousWindow() || !isCurrentWindowLive() || isCurrentWindowSeekable())
&& !isPlayingAd()) && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_NEXT_WINDOW, hasNext() && !isPlayingAd()) .addIf(COMMAND_SEEK_TO_NEXT_WINDOW, hasNextWindow() && !isPlayingAd())
.addIf( .addIf(
COMMAND_SEEK_TO_NEXT, COMMAND_SEEK_TO_NEXT,
!getCurrentTimeline().isEmpty() !getCurrentTimeline().isEmpty()
&& (hasNext() || (isCurrentWindowLive() && isCurrentWindowDynamic())) && (hasNextWindow() || (isCurrentWindowLive() && isCurrentWindowDynamic()))
&& !isPlayingAd()) && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_WINDOW, !isPlayingAd()) .addIf(COMMAND_SEEK_TO_WINDOW, !isPlayingAd())
.addIf(COMMAND_SEEK_BACK, isCurrentWindowSeekable() && !isPlayingAd()) .addIf(COMMAND_SEEK_BACK, isCurrentWindowSeekable() && !isPlayingAd())
......
...@@ -55,7 +55,7 @@ public interface ControlDispatcher { ...@@ -55,7 +55,7 @@ public interface ControlDispatcher {
boolean dispatchSeekTo(Player player, int windowIndex, long positionMs); 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. * @param player The {@link Player} to which the operation should be dispatched.
* @return True if the operation was dispatched. False if suppressed. * @return True if the operation was dispatched. False if suppressed.
...@@ -63,7 +63,7 @@ public interface ControlDispatcher { ...@@ -63,7 +63,7 @@ public interface ControlDispatcher {
boolean dispatchPrevious(Player player); 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. * @param player The {@link Player} to which the operation should be dispatched.
* @return True if the operation was dispatched. False if suppressed. * @return True if the operation was dispatched. False if suppressed.
......
...@@ -75,10 +75,10 @@ public class DefaultControlDispatcher implements ControlDispatcher { ...@@ -75,10 +75,10 @@ public class DefaultControlDispatcher implements ControlDispatcher {
} }
boolean isUnseekableLiveStream = boolean isUnseekableLiveStream =
player.isCurrentWindowLive() && !player.isCurrentWindowSeekable(); player.isCurrentWindowLive() && !player.isCurrentWindowSeekable();
if (player.hasPrevious() if (player.hasPreviousWindow()
&& (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS
|| isUnseekableLiveStream)) { || isUnseekableLiveStream)) {
player.previous(); player.seekToPreviousWindow();
} else if (!isUnseekableLiveStream) { } else if (!isUnseekableLiveStream) {
player.seekTo(/* positionMs= */ 0); player.seekTo(/* positionMs= */ 0);
} }
...@@ -91,8 +91,8 @@ public class DefaultControlDispatcher implements ControlDispatcher { ...@@ -91,8 +91,8 @@ public class DefaultControlDispatcher implements ControlDispatcher {
if (timeline.isEmpty() || player.isPlayingAd()) { if (timeline.isEmpty() || player.isPlayingAd()) {
return true; return true;
} }
if (player.hasNext()) { if (player.hasNextWindow()) {
player.next(); player.seekToNextWindow();
} else if (player.isCurrentWindowLive() && player.isCurrentWindowDynamic()) { } else if (player.isCurrentWindowLive() && player.isCurrentWindowDynamic()) {
player.seekToDefaultPosition(); player.seekToDefaultPosition();
} }
......
...@@ -267,17 +267,29 @@ public class ForwardingPlayer implements Player { ...@@ -267,17 +267,29 @@ public class ForwardingPlayer implements Player {
player.seekForward(); player.seekForward();
} }
@Deprecated
@Override @Override
public boolean hasPrevious() { public boolean hasPrevious() {
return player.hasPrevious(); return player.hasPrevious();
} }
@Override @Override
public boolean hasPreviousWindow() {
return player.hasPreviousWindow();
}
@Deprecated
@Override
public void previous() { public void previous() {
player.previous(); player.previous();
} }
@Override @Override
public void seekToPreviousWindow() {
player.seekToPreviousWindow();
}
@Override
public void seekToPrevious() { public void seekToPrevious() {
player.seekToPrevious(); player.seekToPrevious();
} }
...@@ -287,17 +299,29 @@ public class ForwardingPlayer implements Player { ...@@ -287,17 +299,29 @@ public class ForwardingPlayer implements Player {
return player.getMaxSeekToPreviousPosition(); return player.getMaxSeekToPreviousPosition();
} }
@Deprecated
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return player.hasNext(); return player.hasNext();
} }
@Override @Override
public boolean hasNextWindow() {
return player.hasNextWindow();
}
@Deprecated
@Override
public void next() { public void next() {
player.next(); player.next();
} }
@Override @Override
public void seekToNextWindow() {
player.seekToNextWindow();
}
@Override
public void seekToNext() { public void seekToNext() {
player.seekToNext(); player.seekToNext();
} }
......
...@@ -1542,9 +1542,9 @@ public interface Player { ...@@ -1542,9 +1542,9 @@ public interface Player {
* *
* <p>This method does not execute the command. * <p>This method does not execute the command.
* *
* <p>Executing a command that is not available (for example, calling {@link #next()} if {@link * <p>Executing a command that is not available (for example, calling {@link #seekToNextWindow()}
* #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor generate a * if {@link #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor
* {@link #getPlayerError()} player error}. * generate a {@link #getPlayerError()} player error}.
* *
* <p>{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are * <p>{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are
* unavailable if there is no such {@link MediaItem}. * unavailable if there is no such {@link MediaItem}.
...@@ -1562,9 +1562,9 @@ public interface Player { ...@@ -1562,9 +1562,9 @@ public interface Player {
* Listener#onAvailableCommandsChanged(Commands)} to get an update when the available commands * Listener#onAvailableCommandsChanged(Commands)} to get an update when the available commands
* change. * change.
* *
* <p>Executing a command that is not available (for example, calling {@link #next()} if {@link * <p>Executing a command that is not available (for example, calling {@link #seekToNextWindow()}
* #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor generate a * if {@link #COMMAND_SEEK_TO_NEXT_WINDOW} is unavailable) will neither throw an exception nor
* {@link #getPlayerError()} player error}. * generate a {@link #getPlayerError()} player error}.
* *
* <p>{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are * <p>{@link #COMMAND_SEEK_TO_PREVIOUS_WINDOW} and {@link #COMMAND_SEEK_TO_NEXT_WINDOW} are
* unavailable if there is no such {@link MediaItem}. * unavailable if there is no such {@link MediaItem}.
...@@ -1750,6 +1750,10 @@ public interface Player { ...@@ -1750,6 +1750,10 @@ public interface Player {
/** Seeks forward in the current window by {@link #getSeekForwardIncrement()} milliseconds. */ /** Seeks forward in the current window by {@link #getSeekForwardIncrement()} milliseconds. */
void seekForward(); 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 * Returns whether a previous window exists, which may depend on the current repeat mode and
* whether shuffle mode is enabled. * whether shuffle mode is enabled.
...@@ -1758,18 +1762,22 @@ public interface Player { ...@@ -1758,18 +1762,22 @@ public interface Player {
* the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
* details. * 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 * 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 * mode and whether shuffle mode is enabled. Does nothing if {@link #hasPreviousWindow()} is
* false}. * {@code false}.
* *
* <p>Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * <p>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 * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
* details. * details.
*/ */
void previous(); void seekToPreviousWindow();
/** /**
* Returns the maximum position for which {@link #seekToPrevious()} seeks to the previous window, * Returns the maximum position for which {@link #seekToPrevious()} seeks to the previous window,
...@@ -1788,11 +1796,11 @@ public interface Player { ...@@ -1788,11 +1796,11 @@ public interface Player {
* <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and {@link * <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and {@link
* #isCurrentWindowSeekable() unseekable}, then: * #isCurrentWindowSeekable() unseekable}, then:
* <ul> * <ul>
* <li>If {@link #hasPrevious() a previous window exists}, seeks to the default position * <li>If {@link #hasPreviousWindow() a previous window exists}, seeks to the default
* of the previous window. * position of the previous window.
* <li>Otherwise, does nothing. * <li>Otherwise, does nothing.
* </ul> * </ul>
* <li>Otherwise, if {@link #hasPrevious() a previous window exists} and the {@link * <li>Otherwise, if {@link #hasPreviousWindow() a previous window exists} and the {@link
* #getCurrentPosition() current position} is less than {@link * #getCurrentPosition() current position} is less than {@link
* #getMaxSeekToPreviousPosition()}, seeks to the default position of the previous window. * #getMaxSeekToPreviousPosition()}, seeks to the default position of the previous window.
* <li>Otherwise, seeks to 0 in the current window. * <li>Otherwise, seeks to 0 in the current window.
...@@ -1800,6 +1808,10 @@ public interface Player { ...@@ -1800,6 +1808,10 @@ public interface Player {
*/ */
void seekToPrevious(); 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 * Returns whether a next window exists, which may depend on the current repeat mode and whether
* shuffle mode is enabled. * shuffle mode is enabled.
...@@ -1808,25 +1820,29 @@ public interface Player { ...@@ -1808,25 +1820,29 @@ public interface Player {
* the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
* details. * 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 * 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}.
* *
* <p>Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * <p>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 * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
* details. * details.
*/ */
void next(); void seekToNextWindow();
/** /**
* Seeks to a later position in the current or next window (if available). More precisely: * Seeks to a later position in the current or next window (if available). More precisely:
* *
* <ul> * <ul>
* <li>If the timeline is empty or seeking is not possible, does nothing. * <li>If the timeline is empty or seeking is not possible, does nothing.
* <li>Otherwise, if {@link #hasNext() a next window exists}, seeks to the default position of * <li>Otherwise, if {@link #hasNextWindow() a next window exists}, seeks to the default
* the next window. * position of the next window.
* <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and has not * <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and has not
* ended, seeks to the live edge of the current window. * ended, seeks to the live edge of the current window.
* <li>Otherwise, does nothing. * <li>Otherwise, does nothing.
...@@ -1967,9 +1983,9 @@ public interface Player { ...@@ -1967,9 +1983,9 @@ public interface Player {
int getCurrentWindowIndex(); int getCurrentWindowIndex();
/** /**
* Returns the index of the window that will be played if {@link #next()} is called, which may * Returns the index of the window that will be played if {@link #seekToNextWindow()} is called,
* depend on the current repeat mode and whether shuffle mode is enabled. Returns {@link * which may depend on the current repeat mode and whether shuffle mode is enabled. Returns {@link
* C#INDEX_UNSET} if {@link #hasNext()} is {@code false}. * C#INDEX_UNSET} if {@link #hasNextWindow()} is {@code false}.
* *
* <p>Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * <p>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 * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
...@@ -1978,9 +1994,9 @@ public interface Player { ...@@ -1978,9 +1994,9 @@ public interface Player {
int getNextWindowIndex(); int getNextWindowIndex();
/** /**
* Returns the index of the window that will be played if {@link #previous()} is called, which may * Returns the index of the window that will be played if {@link #seekToPreviousWindow()} is
* depend on the current repeat mode and whether shuffle mode is enabled. Returns {@link * called, which may depend on the current repeat mode and whether shuffle mode is enabled.
* C#INDEX_UNSET} if {@link #hasPrevious()} is {@code false}. * Returns {@link C#INDEX_UNSET} if {@link #hasPreviousWindow()} is {@code false}.
* *
* <p>Note: When the repeat mode is {@link #REPEAT_MODE_ONE}, this method behaves the same as when * <p>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 * the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
......
...@@ -9341,7 +9341,7 @@ public final class ExoPlayerTest { ...@@ -9341,7 +9341,7 @@ public final class ExoPlayerTest {
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Seek to default position in second stream. // Seek to default position in second stream.
player.next(); player.seekToNextWindow();
// Play until close to the end of the available live window. // Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000); TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset(); long liveOffsetAtEnd = player.getCurrentLiveOffset();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment