Update most Player parameter & doc references from Window to MediaItem

Only deprecated references remain.

Usages of the deprecated methods will be migrated in a follow-up change.

#minor-release

PiperOrigin-RevId: 405927141
This commit is contained in:
ibaker 2021-10-27 18:51:03 +01:00 committed by Ian Baker
parent b60acca872
commit d83fe03d88
10 changed files with 98 additions and 100 deletions

View File

@ -326,10 +326,9 @@ public final class CastPlayer extends BasePlayer {
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
setMediaItemsInternal(
toMediaQueueItems(mediaItems), startWindowIndex, startPositionMs, repeatMode.value);
toMediaQueueItems(mediaItems), startIndex, startPositionMs, repeatMode.value);
}
@Override
@ -440,23 +439,23 @@ public final class CastPlayer extends BasePlayer {
// don't implement onPositionDiscontinuity().
@SuppressWarnings("deprecation")
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
MediaStatus mediaStatus = getMediaStatus();
// We assume the default position is 0. There is no support for seeking to the default position
// in RemoteMediaClient.
positionMs = positionMs != C.TIME_UNSET ? positionMs : 0;
if (mediaStatus != null) {
if (getCurrentWindowIndex() != windowIndex) {
if (getCurrentWindowIndex() != mediaItemIndex) {
remoteMediaClient
.queueJumpToItem(
(int) currentTimeline.getPeriod(windowIndex, period).uid, positionMs, null)
(int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null)
.setResultCallback(seekResultCallback);
} else {
remoteMediaClient.seek(positionMs).setResultCallback(seekResultCallback);
}
PositionInfo oldPosition = getCurrentPositionInfo();
pendingSeekCount++;
pendingSeekWindowIndex = windowIndex;
pendingSeekWindowIndex = mediaItemIndex;
pendingSeekPositionMs = positionMs;
PositionInfo newPosition = getCurrentPositionInfo();
listeners.queueEvent(
@ -468,7 +467,7 @@ public final class CastPlayer extends BasePlayer {
if (oldPosition.mediaItemIndex != newPosition.mediaItemIndex) {
// TODO(internal b/182261884): queue `onMediaItemTransition` event when the media item is
// repeated.
MediaItem mediaItem = getCurrentTimeline().getWindow(windowIndex, window).mediaItem;
MediaItem mediaItem = getCurrentTimeline().getWindow(mediaItemIndex, window).mediaItem;
listeners.queueEvent(
Player.EVENT_MEDIA_ITEM_TRANSITION,
listener ->

View File

@ -124,8 +124,8 @@ public abstract class BasePlayer implements Player {
}
@Override
public final void seekToDefaultPosition(int windowIndex) {
seekTo(windowIndex, /* positionMs= */ C.TIME_UNSET);
public final void seekToDefaultPosition(int mediaItemIndex) {
seekTo(mediaItemIndex, /* positionMs= */ C.TIME_UNSET);
}
@Override

View File

@ -65,9 +65,8 @@ public class ForwardingPlayer implements Player {
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
player.setMediaItems(mediaItems, startWindowIndex, startPositionMs);
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
player.setMediaItems(mediaItems, startIndex, startPositionMs);
}
@Override
@ -222,8 +221,8 @@ public class ForwardingPlayer implements Player {
}
@Override
public void seekToDefaultPosition(int windowIndex) {
player.seekToDefaultPosition(windowIndex);
public void seekToDefaultPosition(int mediaItemIndex) {
player.seekToDefaultPosition(mediaItemIndex);
}
@Override
@ -232,8 +231,8 @@ public class ForwardingPlayer implements Player {
}
@Override
public void seekTo(int windowIndex, long positionMs) {
player.seekTo(windowIndex, positionMs);
public void seekTo(int mediaItemIndex, long positionMs) {
player.seekTo(mediaItemIndex, positionMs);
}
@Override

View File

@ -1512,16 +1512,16 @@ public interface Player {
* Clears the playlist and adds the specified {@link MediaItem MediaItems}.
*
* @param mediaItems The new {@link MediaItem MediaItems}.
* @param startWindowIndex The window index to start playback from. If {@link C#INDEX_UNSET} is
* passed, the current position is not reset.
* @param startIndex The {@link MediaItem} index to start playback from. If {@link C#INDEX_UNSET}
* is passed, the current position is not reset.
* @param startPositionMs The position in milliseconds to start playback from. If {@link
* C#TIME_UNSET} is passed, the default position of the given window is used. In any case, if
* {@code startWindowIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored and the
* position is not reset at all.
* @throws IllegalSeekPositionException If the provided {@code startWindowIndex} is not within the
* C#TIME_UNSET} is passed, the default position of the given {@link MediaItem} is used. In
* any case, if {@code startIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored
* and the position is not reset at all.
* @throws IllegalSeekPositionException If the provided {@code startIndex} is not within the
* bounds of the list of media items.
*/
void setMediaItems(List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs);
void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs);
/**
* Clears the playlist, adds the specified {@link MediaItem} and resets the position to the
@ -1648,9 +1648,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 #seekToNextWindow()}
* if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} 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
* #seekToNextMediaItem()} if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) will
* neither throw an exception nor generate a {@link #getPlayerError()} player error}.
*
* <p>{@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} and {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM}
* are unavailable if there is no such {@link MediaItem}.
@ -1755,14 +1755,14 @@ public interface Player {
int getRepeatMode();
/**
* Sets whether shuffling of windows is enabled.
* Sets whether shuffling of media items is enabled.
*
* @param shuffleModeEnabled Whether shuffling is enabled.
*/
void setShuffleModeEnabled(boolean shuffleModeEnabled);
/**
* Returns whether shuffling of windows is enabled.
* Returns whether shuffling of media items is enabled.
*
* @see Listener#onShuffleModeEnabledChanged(boolean)
*/
@ -1777,42 +1777,42 @@ public interface Player {
boolean isLoading();
/**
* Seeks to the default position associated with the current window. The position can depend on
* the type of media being played. For live streams it will typically be the live edge of the
* window. For other streams it will typically be the start of the window.
* Seeks to the default position associated with the current {@link MediaItem}. The position can
* depend on the type of media being played. For live streams it will typically be the live edge.
* For other streams it will typically be the start.
*/
void seekToDefaultPosition();
/**
* Seeks to the default position associated with the specified window. The position can depend on
* the type of media being played. For live streams it will typically be the live edge of the
* window. For other streams it will typically be the start of the window.
* Seeks to the default position associated with the specified {@link MediaItem}. The position can
* depend on the type of media being played. For live streams it will typically be the live edge.
* For other streams it will typically be the start.
*
* @param windowIndex The index of the window whose associated default position should be seeked
* to.
* @param mediaItemIndex The index of the {@link MediaItem} whose associated default position
* should be seeked to.
* @throws IllegalSeekPositionException If the player has a non-empty timeline and the provided
* {@code windowIndex} is not within the bounds of the current timeline.
* {@code mediaItemIndex} is not within the bounds of the current timeline.
*/
void seekToDefaultPosition(int windowIndex);
void seekToDefaultPosition(int mediaItemIndex);
/**
* Seeks to a position specified in milliseconds in the current window.
* Seeks to a position specified in milliseconds in the current {@link MediaItem}.
*
* @param positionMs The seek position in the current window, or {@link C#TIME_UNSET} to seek to
* the window's default position.
* @param positionMs The seek position in the current {@link MediaItem}, or {@link C#TIME_UNSET}
* to seek to the media item's default position.
*/
void seekTo(long positionMs);
/**
* Seeks to a position specified in milliseconds in the specified window.
* Seeks to a position specified in milliseconds in the specified {@link MediaItem}.
*
* @param windowIndex The index of the window.
* @param positionMs The seek position in the specified window, or {@link C#TIME_UNSET} to seek to
* the window's default position.
* @param mediaItemIndex The index of the {@link MediaItem}.
* @param positionMs The seek position in the specified {@link MediaItem}, or {@link C#TIME_UNSET}
* to seek to the media item's default position.
* @throws IllegalSeekPositionException If the player has a non-empty timeline and the provided
* {@code windowIndex} is not within the bounds of the current timeline.
* {@code mediaItemIndex} is not within the bounds of the current timeline.
*/
void seekTo(int windowIndex, long positionMs);
void seekTo(int mediaItemIndex, long positionMs);
/**
* Returns the {@link #seekBack()} increment.
@ -1822,7 +1822,9 @@ public interface Player {
*/
long getSeekBackIncrement();
/** Seeks back in the current window by {@link #getSeekBackIncrement()} milliseconds. */
/**
* Seeks back in the current {@link MediaItem} by {@link #getSeekBackIncrement()} milliseconds.
*/
void seekBack();
/**
@ -1833,7 +1835,10 @@ public interface Player {
*/
long getSeekForwardIncrement();
/** Seeks forward in the current window by {@link #getSeekForwardIncrement()} milliseconds. */
/**
* Seeks forward in the current {@link MediaItem} by {@link #getSeekForwardIncrement()}
* milliseconds.
*/
void seekForward();
/** @deprecated Use {@link #hasPreviousMediaItem()} instead. */
@ -1919,8 +1924,8 @@ public interface Player {
boolean hasNextWindow();
/**
* Returns whether a next window exists, which may depend on the current repeat mode and whether
* shuffle mode is enabled.
* Returns whether a next {@link MediaItem} exists, which may depend on the current repeat mode
* and whether shuffle mode is enabled.
*
* <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
@ -1939,9 +1944,9 @@ public interface Player {
void seekToNextWindow();
/**
* 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 #hasNextMediaItem()} is {@code
* false}.
* Seeks to the default position of the next {@link MediaItem}, which may depend on the current
* repeat mode and whether shuffle mode is enabled. Does nothing if {@link #hasNextMediaItem()} 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
@ -1957,8 +1962,8 @@ public interface Player {
* <li>If the timeline is empty or seeking is not possible, does nothing.
* <li>Otherwise, if {@link #hasNextMediaItem() a next media item exists}, seeks to the default
* position of the next {@link MediaItem}.
* <li>Otherwise, if the current window is {@link #isCurrentMediaItemLive() live} and has not
* ended, seeks to the live edge of the current {@link MediaItem}.
* <li>Otherwise, if the current {@link MediaItem} is {@link #isCurrentMediaItemLive() live} and
* has not ended, seeks to the live edge of the current {@link MediaItem}.
* <li>Otherwise, does nothing.
* </ul>
*/

View File

@ -421,9 +421,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
setMediaSources(createMediaSources(mediaItems), startWindowIndex, startPositionMs);
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
setMediaSources(createMediaSources(mediaItems), startIndex, startPositionMs);
}
public void setMediaSource(MediaSource mediaSource) {
@ -655,10 +654,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
Timeline timeline = playbackInfo.timeline;
if (windowIndex < 0 || (!timeline.isEmpty() && windowIndex >= timeline.getWindowCount())) {
throw new IllegalSeekPositionException(timeline, windowIndex, positionMs);
if (mediaItemIndex < 0
|| (!timeline.isEmpty() && mediaItemIndex >= timeline.getWindowCount())) {
throw new IllegalSeekPositionException(timeline, mediaItemIndex, positionMs);
}
pendingOperationAcks++;
if (isPlayingAd()) {
@ -681,8 +681,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition(
newPlaybackInfo,
timeline,
getPeriodPositionOrMaskWindowPosition(timeline, windowIndex, positionMs));
internalPlayer.seekTo(timeline, windowIndex, C.msToUs(positionMs));
getPeriodPositionOrMaskWindowPosition(timeline, mediaItemIndex, positionMs));
internalPlayer.seekTo(timeline, mediaItemIndex, C.msToUs(positionMs));
updatePlaybackInfo(
newPlaybackInfo,
/* ignored */ TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,

View File

@ -1097,10 +1097,9 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
verifyApplicationThread();
player.setMediaItems(mediaItems, startWindowIndex, startPositionMs);
player.setMediaItems(mediaItems, startIndex, startPositionMs);
}
@Override
@ -1246,10 +1245,10 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
verifyApplicationThread();
analyticsCollector.notifySeekStarted();
player.seekTo(windowIndex, positionMs);
player.seekTo(mediaItemIndex, positionMs);
}
@Override

View File

@ -520,13 +520,13 @@ public class MediaController implements Player {
}
@Override
public void seekToDefaultPosition(int windowIndex) {
public void seekToDefaultPosition(int mediaItemIndex) {
verifyApplicationThread();
if (!isConnected()) {
Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
return;
}
impl.seekToDefaultPosition(windowIndex);
impl.seekToDefaultPosition(mediaItemIndex);
}
@Override
@ -540,13 +540,13 @@ public class MediaController implements Player {
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
verifyApplicationThread();
if (!isConnected()) {
Log.w(TAG, "The controller is not connected. Ignoring seekTo().");
return;
}
impl.seekTo(windowIndex, positionMs);
impl.seekTo(mediaItemIndex, positionMs);
}
/**
@ -946,8 +946,7 @@ public class MediaController implements Player {
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
verifyApplicationThread();
checkNotNull(mediaItems, "mediaItems must not be null");
for (int i = 0; i < mediaItems.size(); i++) {
@ -957,7 +956,7 @@ public class MediaController implements Player {
Log.w(TAG, "The controller is not connected. Ignoring setMediaItems().");
return;
}
impl.setMediaItems(mediaItems, startWindowIndex, startPositionMs);
impl.setMediaItems(mediaItems, startIndex, startPositionMs);
}
/**
@ -1287,7 +1286,7 @@ public class MediaController implements Player {
*
* <p>Interoperability: When connected to {@link
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
* C#INDEX_UNSET} even when {@link #hasPreviousWindow()} is {@code true}.
* C#INDEX_UNSET} even when {@link #hasPreviousMediaItem()} is {@code true}.
*/
@Override
public int getPreviousMediaItemIndex() {
@ -1308,7 +1307,7 @@ public class MediaController implements Player {
*
* <p>Interoperability: When connected to {@link
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
* C#INDEX_UNSET} even when {@link #hasNextWindow()} is {@code true}.
* C#INDEX_UNSET} even when {@link #hasNextMediaItem()} is {@code true}.
*/
@Override
public int getNextMediaItemIndex() {
@ -1424,8 +1423,8 @@ public class MediaController implements Player {
* {@inheritDoc}
*
* <p>Interoperability: When connected to {@link
* android.support.v4.media.session.MediaSessionCompat}, it wouldn't update current window index
* immediately because previous window index is unknown.
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
* index immediately because the previous media item index is unknown.
*/
@Override
public void seekToPrevious() {
@ -1453,8 +1452,8 @@ public class MediaController implements Player {
* {@inheritDoc}
*
* <p>Interoperability: When connected to {@link
* android.support.v4.media.session.MediaSessionCompat}, it wouldn't update current window index
* immediately because previous window index is unknown.
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
* index immediately because the previous media item index is unknown.
*/
@Override
public void seekToNext() {

View File

@ -106,9 +106,9 @@ import java.util.List;
}
@Override
public void seekToDefaultPosition(int windowIndex) {
public void seekToDefaultPosition(int mediaItemIndex) {
verifyApplicationThread();
super.seekToDefaultPosition(windowIndex);
super.seekToDefaultPosition(mediaItemIndex);
}
@Override
@ -118,9 +118,9 @@ import java.util.List;
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
verifyApplicationThread();
super.seekTo(windowIndex, positionMs);
super.seekTo(mediaItemIndex, positionMs);
}
@Override
@ -334,10 +334,9 @@ import java.util.List;
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
verifyApplicationThread();
super.setMediaItems(mediaItems, startWindowIndex, startPositionMs);
super.setMediaItems(mediaItems, startIndex, startPositionMs);
}
@Override

View File

@ -270,9 +270,9 @@ public class MockPlayer implements Player {
}
@Override
public void seekToDefaultPosition(int windowIndex) {
public void seekToDefaultPosition(int mediaItemIndex) {
seekToDefaultPositionWithWindowIndexCalled = true;
seekWindowIndex = windowIndex;
seekWindowIndex = mediaItemIndex;
countDownLatch.countDown();
}
@ -284,9 +284,9 @@ public class MockPlayer implements Player {
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
seekToWithWindowIndexCalled = true;
seekWindowIndex = windowIndex;
seekWindowIndex = mediaItemIndex;
seekPositionMs = positionMs;
countDownLatch.countDown();
}
@ -665,11 +665,10 @@ public class MockPlayer implements Player {
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
setMediaItemsWithStartWindowIndexCalled = true;
this.mediaItems = mediaItems;
this.startWindowIndex = startWindowIndex;
this.startWindowIndex = startIndex;
this.startPositionMs = startPositionMs;
countDownLatch.countDown();
}

View File

@ -208,8 +208,7 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public void setMediaItems(
List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs) {
public void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
throw new UnsupportedOperationException();
}
@ -400,7 +399,7 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public void seekTo(int windowIndex, long positionMs) {
public void seekTo(int mediaItemIndex, long positionMs) {
throw new UnsupportedOperationException();
}