From ad39f38995d7bc9bb8588e203e90fbcb5de895fe Mon Sep 17 00:00:00 2001 From: ibaker Date: Wed, 27 Oct 2021 18:51:03 +0100 Subject: [PATCH] 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 --- .../exoplayer2/ext/cast/CastPlayer.java | 15 ++-- .../google/android/exoplayer2/BasePlayer.java | 4 +- .../android/exoplayer2/ForwardingPlayer.java | 13 ++- .../com/google/android/exoplayer2/Player.java | 85 ++++++++++--------- .../android/exoplayer2/ExoPlayerImpl.java | 16 ++-- .../android/exoplayer2/SimpleExoPlayer.java | 9 +- .../exoplayer2/testutil/StubExoPlayer.java | 5 +- 7 files changed, 74 insertions(+), 73 deletions(-) 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 25e792f16b..1bf2cd410b 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 @@ -324,10 +324,9 @@ public final class CastPlayer extends BasePlayer { } @Override - public void setMediaItems( - List mediaItems, int startWindowIndex, long startPositionMs) { + public void setMediaItems(List mediaItems, int startIndex, long startPositionMs) { setMediaItemsInternal( - toMediaQueueItems(mediaItems), startWindowIndex, startPositionMs, repeatMode.value); + toMediaQueueItems(mediaItems), startIndex, startPositionMs, repeatMode.value); } @Override @@ -438,23 +437,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( @@ -466,7 +465,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 -> 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 06d675d59f..b60e4a3a7e 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 @@ -122,8 +122,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 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 62e113481d..6b2b7426d8 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 @@ -69,9 +69,8 @@ public class ForwardingPlayer implements Player { } @Override - public void setMediaItems( - List mediaItems, int startWindowIndex, long startPositionMs) { - player.setMediaItems(mediaItems, startWindowIndex, startPositionMs); + public void setMediaItems(List mediaItems, int startIndex, long startPositionMs) { + player.setMediaItems(mediaItems, startIndex, startPositionMs); } @Override @@ -226,8 +225,8 @@ public class ForwardingPlayer implements Player { } @Override - public void seekToDefaultPosition(int windowIndex) { - player.seekToDefaultPosition(windowIndex); + public void seekToDefaultPosition(int mediaItemIndex) { + player.seekToDefaultPosition(mediaItemIndex); } @Override @@ -236,8 +235,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 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 3a14e03d1b..5c60097eb0 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 @@ -1507,16 +1507,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 mediaItems, int startWindowIndex, long startPositionMs); + void setMediaItems(List mediaItems, int startIndex, long startPositionMs); /** * Clears the playlist, adds the specified {@link MediaItem} and resets the position to the @@ -1643,9 +1643,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 #seekToNextWindow()} - * if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} 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 + * #seekToNextMediaItem()} if {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} is unavailable) will + * neither throw an exception nor generate a {@link #getPlayerError()} player error}. * *

{@link #COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM} and {@link #COMMAND_SEEK_TO_NEXT_MEDIA_ITEM} * are unavailable if there is no such {@link MediaItem}. @@ -1750,14 +1750,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) */ @@ -1772,42 +1772,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. @@ -1817,7 +1817,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(); /** @@ -1828,7 +1830,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. */ @@ -1908,8 +1913,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. * *

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 @@ -1926,9 +1931,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}. * *

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 @@ -1944,8 +1949,8 @@ public interface Player { *

  • If the timeline is empty or seeking is not possible, does nothing. *
  • Otherwise, if {@link #hasNextMediaItem() a next media item exists}, seeks to the default * position of the next {@link MediaItem}. - *
  • Otherwise, if the current window is {@link #isCurrentMediaItemLive() live} and has not - * ended, seeks to the live edge of the current {@link MediaItem}. + *
  • Otherwise, if the current {@link MediaItem} is {@link #isCurrentMediaItemLive() live} and + * has not ended, seeks to the live edge of the current {@link MediaItem}. *
  • Otherwise, does nothing. * */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 78f232e9a5..31fb99dbc2 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -408,9 +408,8 @@ import java.util.concurrent.CopyOnWriteArraySet; } @Override - public void setMediaItems( - List mediaItems, int startWindowIndex, long startPositionMs) { - setMediaSources(createMediaSources(mediaItems), startWindowIndex, startPositionMs); + public void setMediaItems(List mediaItems, int startIndex, long startPositionMs) { + setMediaSources(createMediaSources(mediaItems), startIndex, startPositionMs); } public void setMediaSource(MediaSource mediaSource) { @@ -642,10 +641,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()) { @@ -668,8 +668,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, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index c6fddec392..6a061bef5f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -1086,10 +1086,9 @@ public class SimpleExoPlayer extends BasePlayer } @Override - public void setMediaItems( - List mediaItems, int startWindowIndex, long startPositionMs) { + public void setMediaItems(List mediaItems, int startIndex, long startPositionMs) { verifyApplicationThread(); - player.setMediaItems(mediaItems, startWindowIndex, startPositionMs); + player.setMediaItems(mediaItems, startIndex, startPositionMs); } @Override @@ -1235,10 +1234,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 diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java index eeb4c5856a..9a5a50d1d3 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java @@ -206,8 +206,7 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer { } @Override - public void setMediaItems( - List mediaItems, int startWindowIndex, long startPositionMs) { + public void setMediaItems(List mediaItems, int startIndex, long startPositionMs) { throw new UnsupportedOperationException(); } @@ -398,7 +397,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(); }