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
This commit is contained in:
kimvde 2021-07-14 09:05:05 +01:00 committed by Oliver Woodman
parent 3670541465
commit ae31ebb143
8 changed files with 113 additions and 46 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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())

View File

@ -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.

View File

@ -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();
}

View File

@ -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();

View File

@ -1542,9 +1542,9 @@ public interface Player {
*
* <p>This method does not execute the command.
*
* <p>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}.
* <p>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}.
*
* <p>{@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.
*
* <p>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}.
* <p>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}.
*
* <p>{@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}.
*
* <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
* 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 {
* <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and {@link
* #isCurrentWindowSeekable() unseekable}, then:
* <ul>
* <li>If {@link #hasPrevious() a previous window exists}, seeks to the default position
* of the previous window.
* <li>If {@link #hasPreviousWindow() a previous window exists}, seeks to the default
* position of the previous window.
* <li>Otherwise, does nothing.
* </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
* #getMaxSeekToPreviousPosition()}, seeks to the default position of the previous window.
* <li>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}.
*
* <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
* details.
*/
void next();
void seekToNextWindow();
/**
* Seeks to a later position in the current or next window (if available). More precisely:
*
* <ul>
* <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
* the next window.
* <li>Otherwise, if {@link #hasNextWindow() a next window exists}, seeks to the default
* position of the next window.
* <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and has not
* ended, seeks to the live edge of the current window.
* <li>Otherwise, does nothing.
@ -1967,9 +1983,9 @@ public interface Player {
int getCurrentWindowIndex();
/**
* Returns the index of the window that will be played if {@link #next()} is called, 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}.
* Returns the index of the window that will be played if {@link #seekToNextWindow()} is called,
* which may depend on the current repeat mode and whether shuffle mode is enabled. Returns {@link
* 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
* the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more
@ -1978,9 +1994,9 @@ public interface Player {
int getNextWindowIndex();
/**
* Returns the index of the window that will be played if {@link #previous()} is called, which may
* depend on the current repeat mode and whether shuffle mode is enabled. Returns {@link
* C#INDEX_UNSET} if {@link #hasPrevious()} is {@code false}.
* Returns the index of the window that will be played if {@link #seekToPreviousWindow()} is
* called, which may depend on the current repeat mode and whether shuffle mode is enabled.
* 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
* the current repeat mode is {@link #REPEAT_MODE_OFF}. See {@link #REPEAT_MODE_ONE} for more

View File

@ -9341,7 +9341,7 @@ public final class ExoPlayerTest {
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Seek to default position in second stream.
player.next();
player.seekToNextWindow();
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();