diff --git a/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java b/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java index 350a23920c..acb6b2c397 100644 --- a/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java +++ b/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java @@ -122,7 +122,7 @@ public static final class Builder { private Size surfaceSize; private boolean newlyRenderedFirstFrame; private Metadata timedMetadata; - private ImmutableList playlistItems; + private ImmutableList playlist; private Timeline timeline; private MediaMetadata playlistMetadata; private int currentMediaItemIndex; @@ -168,7 +168,7 @@ public Builder() { surfaceSize = Size.UNKNOWN; newlyRenderedFirstFrame = false; timedMetadata = new Metadata(/* presentationTimeUs= */ C.TIME_UNSET); - playlistItems = ImmutableList.of(); + playlist = ImmutableList.of(); timeline = Timeline.EMPTY; playlistMetadata = MediaMetadata.EMPTY; currentMediaItemIndex = 0; @@ -214,7 +214,7 @@ private Builder(State state) { this.surfaceSize = state.surfaceSize; this.newlyRenderedFirstFrame = state.newlyRenderedFirstFrame; this.timedMetadata = state.timedMetadata; - this.playlistItems = state.playlistItems; + this.playlist = state.playlist; this.timeline = state.timeline; this.playlistMetadata = state.playlistMetadata; this.currentMediaItemIndex = state.currentMediaItemIndex; @@ -565,21 +565,21 @@ public Builder setTimedMetadata(Metadata timedMetadata) { } /** - * Sets the playlist items. + * Sets the list of {@link MediaItemData media items} in the playlist. * - *

All playlist items must have unique {@linkplain PlaylistItem.Builder#setUid UIDs}. + *

All items must have unique {@linkplain MediaItemData.Builder#setUid UIDs}. * - * @param playlistItems The list of playlist items. + * @param playlist The list of {@link MediaItemData media items} in the playlist. * @return This builder. */ @CanIgnoreReturnValue - public Builder setPlaylist(List playlistItems) { + public Builder setPlaylist(List playlist) { HashSet uids = new HashSet<>(); - for (int i = 0; i < playlistItems.size(); i++) { - checkArgument(uids.add(playlistItems.get(i).uid)); + for (int i = 0; i < playlist.size(); i++) { + checkArgument(uids.add(playlist.get(i).uid)); } - this.playlistItems = ImmutableList.copyOf(playlistItems); - this.timeline = new PlaylistTimeline(this.playlistItems); + this.playlist = ImmutableList.copyOf(playlist); + this.timeline = new PlaylistTimeline(this.playlist); return this; } @@ -598,8 +598,8 @@ public Builder setPlaylistMetadata(MediaMetadata playlistMetadata) { /** * Sets the current media item index. * - *

The media item index must be less than the number of {@linkplain #setPlaylist playlist - * items}, if set. + *

The media item index must be less than the number of {@linkplain #setPlaylist media + * items in the playlist}, if set. * * @param currentMediaItemIndex The current media item index. * @return This builder. @@ -612,15 +612,15 @@ public Builder setCurrentMediaItemIndex(int currentMediaItemIndex) { /** * Sets the current period index, or {@link C#INDEX_UNSET} to assume the first period of the - * current playlist item is played. + * current media item is played. * *

The period index must be less than the total number of {@linkplain - * PlaylistItem.Builder#setPeriods periods} in the playlist, if set, and the period at the - * specified index must be part of the {@linkplain #setCurrentMediaItemIndex current playlist + * MediaItemData.Builder#setPeriods periods} in the media item, if set, and the period at the + * specified index must be part of the {@linkplain #setCurrentMediaItemIndex current media * item}. * * @param currentPeriodIndex The current period index, or {@link C#INDEX_UNSET} to assume the - * first period of the current playlist item is played. + * first period of the current media item is played. * @return This builder. */ @CanIgnoreReturnValue @@ -637,7 +637,7 @@ public Builder setCurrentPeriodIndex(int currentPeriodIndex) { * C#INDEX_UNSET}. * *

Ads indices can only be set if there is a corresponding {@link AdPlaybackState} defined - * in the current {@linkplain PlaylistItem.Builder#setPeriods period}. + * in the current {@linkplain MediaItemData.Builder#setPeriods period}. * * @param adGroupIndex The current ad group index, or {@link C#INDEX_UNSET} if no ad is * playing. @@ -863,9 +863,9 @@ public State build() { public final boolean newlyRenderedFirstFrame; /** The most recent timed metadata. */ public final Metadata timedMetadata; - /** The playlist items. */ - public final ImmutableList playlistItems; - /** The {@link Timeline} derived from the {@linkplain #playlistItems playlist items}. */ + /** The media items in the playlist. */ + public final ImmutableList playlist; + /** The {@link Timeline} derived from the {@link #playlist}. */ public final Timeline timeline; /** The playlist {@link MediaMetadata}. */ public final MediaMetadata playlistMetadata; @@ -873,7 +873,7 @@ public State build() { public final int currentMediaItemIndex; /** * The current period index, or {@link C#INDEX_UNSET} to assume the first period of the current - * playlist item is played. + * media item is played. */ public final int currentPeriodIndex; /** The current ad group index, or {@link C#INDEX_UNSET} if no ad is playing. */ @@ -999,7 +999,7 @@ private State(Builder builder) { this.surfaceSize = builder.surfaceSize; this.newlyRenderedFirstFrame = builder.newlyRenderedFirstFrame; this.timedMetadata = builder.timedMetadata; - this.playlistItems = builder.playlistItems; + this.playlist = builder.playlist; this.timeline = builder.timeline; this.playlistMetadata = builder.playlistMetadata; this.currentMediaItemIndex = builder.currentMediaItemIndex; @@ -1056,7 +1056,7 @@ public boolean equals(@Nullable Object o) { && surfaceSize.equals(state.surfaceSize) && newlyRenderedFirstFrame == state.newlyRenderedFirstFrame && timedMetadata.equals(state.timedMetadata) - && playlistItems.equals(state.playlistItems) + && playlist.equals(state.playlist) && playlistMetadata.equals(state.playlistMetadata) && currentMediaItemIndex == state.currentMediaItemIndex && currentPeriodIndex == state.currentPeriodIndex @@ -1102,7 +1102,7 @@ public int hashCode() { result = 31 * result + surfaceSize.hashCode(); result = 31 * result + (newlyRenderedFirstFrame ? 1 : 0); result = 31 * result + timedMetadata.hashCode(); - result = 31 * result + playlistItems.hashCode(); + result = 31 * result + playlist.hashCode(); result = 31 * result + playlistMetadata.hashCode(); result = 31 * result + currentMediaItemIndex; result = 31 * result + currentPeriodIndex; @@ -1122,28 +1122,28 @@ public int hashCode() { private static final class PlaylistTimeline extends Timeline { - private final ImmutableList playlistItems; + private final ImmutableList playlist; private final int[] firstPeriodIndexByWindowIndex; private final int[] windowIndexByPeriodIndex; private final HashMap periodIndexByUid; - public PlaylistTimeline(ImmutableList playlistItems) { - int playlistItemCount = playlistItems.size(); - this.playlistItems = playlistItems; - this.firstPeriodIndexByWindowIndex = new int[playlistItemCount]; + public PlaylistTimeline(ImmutableList playlist) { + int mediaItemCount = playlist.size(); + this.playlist = playlist; + this.firstPeriodIndexByWindowIndex = new int[mediaItemCount]; int periodCount = 0; - for (int i = 0; i < playlistItemCount; i++) { - PlaylistItem playlistItem = playlistItems.get(i); + for (int i = 0; i < mediaItemCount; i++) { + MediaItemData mediaItemData = playlist.get(i); firstPeriodIndexByWindowIndex[i] = periodCount; - periodCount += getPeriodCountInPlaylistItem(playlistItem); + periodCount += getPeriodCountInMediaItem(mediaItemData); } this.windowIndexByPeriodIndex = new int[periodCount]; this.periodIndexByUid = new HashMap<>(); int periodIndex = 0; - for (int i = 0; i < playlistItemCount; i++) { - PlaylistItem playlistItem = playlistItems.get(i); - for (int j = 0; j < getPeriodCountInPlaylistItem(playlistItem); j++) { - periodIndexByUid.put(playlistItem.getPeriodUid(j), periodIndex); + for (int i = 0; i < mediaItemCount; i++) { + MediaItemData mediaItemData = playlist.get(i); + for (int j = 0; j < getPeriodCountInMediaItem(mediaItemData); j++) { + periodIndexByUid.put(mediaItemData.getPeriodUid(j), periodIndex); windowIndexByPeriodIndex[periodIndex] = i; periodIndex++; } @@ -1152,7 +1152,7 @@ public PlaylistTimeline(ImmutableList playlistItems) { @Override public int getWindowCount() { - return playlistItems.size(); + return playlist.size(); } @Override @@ -1181,7 +1181,7 @@ public int getFirstWindowIndex(boolean shuffleModeEnabled) { @Override public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) { - return playlistItems + return playlist .get(windowIndex) .getWindow(firstPeriodIndexByWindowIndex[windowIndex], window); } @@ -1201,7 +1201,7 @@ public Period getPeriodByUid(Object periodUid, Period period) { public Period getPeriod(int periodIndex, Period period, boolean setIds) { int windowIndex = windowIndexByPeriodIndex[periodIndex]; int periodIndexInWindow = periodIndex - firstPeriodIndexByWindowIndex[windowIndex]; - return playlistItems.get(windowIndex).getPeriod(windowIndex, periodIndexInWindow, period); + return playlist.get(windowIndex).getPeriod(windowIndex, periodIndexInWindow, period); } @Override @@ -1214,21 +1214,22 @@ public int getIndexOfPeriod(Object uid) { public Object getUidOfPeriod(int periodIndex) { int windowIndex = windowIndexByPeriodIndex[periodIndex]; int periodIndexInWindow = periodIndex - firstPeriodIndexByWindowIndex[windowIndex]; - return playlistItems.get(windowIndex).getPeriodUid(periodIndexInWindow); + return playlist.get(windowIndex).getPeriodUid(periodIndexInWindow); } - private static int getPeriodCountInPlaylistItem(PlaylistItem playlistItem) { - return playlistItem.periods.isEmpty() ? 1 : playlistItem.periods.size(); + private static int getPeriodCountInMediaItem(MediaItemData mediaItemData) { + return mediaItemData.periods.isEmpty() ? 1 : mediaItemData.periods.size(); } } /** - * An immutable description of a playlist item, containing both static setup information like - * {@link MediaItem} and dynamic data that is generally read from the media like the duration. + * An immutable description of an item in the playlist, containing both static setup information + * like {@link MediaItem} and dynamic data that is generally read from the media like the + * duration. */ - protected static final class PlaylistItem { + protected static final class MediaItemData { - /** A builder for {@link PlaylistItem} objects. */ + /** A builder for {@link MediaItemData} objects. */ public static final class Builder { private Object uid; @@ -1251,7 +1252,7 @@ public static final class Builder { /** * Creates the builder. * - * @param uid The unique identifier of the playlist item within a playlist. This value will be + * @param uid The unique identifier of the media item within a playlist. This value will be * set as {@link Timeline.Window#uid} for this item. */ public Builder(Object uid) { @@ -1273,31 +1274,31 @@ public Builder(Object uid) { periods = ImmutableList.of(); } - private Builder(PlaylistItem playlistItem) { - this.uid = playlistItem.uid; - this.tracks = playlistItem.tracks; - this.mediaItem = playlistItem.mediaItem; - this.mediaMetadata = playlistItem.mediaMetadata; - this.manifest = playlistItem.manifest; - this.liveConfiguration = playlistItem.liveConfiguration; - this.presentationStartTimeMs = playlistItem.presentationStartTimeMs; - this.windowStartTimeMs = playlistItem.windowStartTimeMs; - this.elapsedRealtimeEpochOffsetMs = playlistItem.elapsedRealtimeEpochOffsetMs; - this.isSeekable = playlistItem.isSeekable; - this.isDynamic = playlistItem.isDynamic; - this.defaultPositionUs = playlistItem.defaultPositionUs; - this.durationUs = playlistItem.durationUs; - this.positionInFirstPeriodUs = playlistItem.positionInFirstPeriodUs; - this.isPlaceholder = playlistItem.isPlaceholder; - this.periods = playlistItem.periods; + private Builder(MediaItemData mediaItemData) { + this.uid = mediaItemData.uid; + this.tracks = mediaItemData.tracks; + this.mediaItem = mediaItemData.mediaItem; + this.mediaMetadata = mediaItemData.mediaMetadata; + this.manifest = mediaItemData.manifest; + this.liveConfiguration = mediaItemData.liveConfiguration; + this.presentationStartTimeMs = mediaItemData.presentationStartTimeMs; + this.windowStartTimeMs = mediaItemData.windowStartTimeMs; + this.elapsedRealtimeEpochOffsetMs = mediaItemData.elapsedRealtimeEpochOffsetMs; + this.isSeekable = mediaItemData.isSeekable; + this.isDynamic = mediaItemData.isDynamic; + this.defaultPositionUs = mediaItemData.defaultPositionUs; + this.durationUs = mediaItemData.durationUs; + this.positionInFirstPeriodUs = mediaItemData.positionInFirstPeriodUs; + this.isPlaceholder = mediaItemData.isPlaceholder; + this.periods = mediaItemData.periods; } /** - * Sets the unique identifier of this playlist item within a playlist. + * Sets the unique identifier of this media item within a playlist. * *

This value will be set as {@link Timeline.Window#uid} for this item. * - * @param uid The unique identifier of this playlist item within a playlist. + * @param uid The unique identifier of this media item within a playlist. * @return This builder. */ @CanIgnoreReturnValue @@ -1307,9 +1308,9 @@ public Builder setUid(Object uid) { } /** - * Sets the {@link Tracks} of this playlist item. + * Sets the {@link Tracks} of this media item. * - * @param tracks The {@link Tracks} of this playlist item. + * @param tracks The {@link Tracks} of this media item. * @return This builder. */ @CanIgnoreReturnValue @@ -1319,9 +1320,9 @@ public Builder setTracks(Tracks tracks) { } /** - * Sets the {@link MediaItem} for this playlist item. + * Sets the {@link MediaItem}. * - * @param mediaItem The {@link MediaItem} for this playlist item. + * @param mediaItem The {@link MediaItem}. * @return This builder. */ @CanIgnoreReturnValue @@ -1351,9 +1352,9 @@ public Builder setMediaMetadata(@Nullable MediaMetadata mediaMetadata) { } /** - * Sets the manifest of the playlist item. + * Sets the manifest of the media item. * - * @param manifest The manifest of the playlist item, or null if not applicable. + * @param manifest The manifest of the media item, or null if not applicable. * @return This builder. */ @CanIgnoreReturnValue @@ -1363,11 +1364,10 @@ public Builder setManifest(@Nullable Object manifest) { } /** - * Sets the active {@link MediaItem.LiveConfiguration}, or null if the playlist item is not - * live. + * Sets the active {@link MediaItem.LiveConfiguration}, or null if the media item is not live. * * @param liveConfiguration The active {@link MediaItem.LiveConfiguration}, or null if the - * playlist item is not live. + * media item is not live. * @return This builder. */ @CanIgnoreReturnValue @@ -1428,9 +1428,9 @@ public Builder setElapsedRealtimeEpochOffsetMs(long elapsedRealtimeEpochOffsetMs } /** - * Sets whether it's possible to seek within this playlist item. + * Sets whether it's possible to seek within this media item. * - * @param isSeekable Whether it's possible to seek within this playlist item. + * @param isSeekable Whether it's possible to seek within this media item. * @return This builder. */ @CanIgnoreReturnValue @@ -1440,9 +1440,9 @@ public Builder setIsSeekable(boolean isSeekable) { } /** - * Sets whether this playlist item may change over time, for example a moving live window. + * Sets whether this media item may change over time, for example a moving live window. * - * @param isDynamic Whether this playlist item may change over time, for example a moving live + * @param isDynamic Whether this media item may change over time, for example a moving live * window. * @return This builder. */ @@ -1453,13 +1453,13 @@ public Builder setIsDynamic(boolean isDynamic) { } /** - * Sets the default position relative to the start of the playlist item at which to begin + * Sets the default position relative to the start of the media item at which to begin * playback, in microseconds. * *

The default position must be less or equal to the {@linkplain #setDurationUs duration}, * is set. * - * @param defaultPositionUs The default position relative to the start of the playlist item at + * @param defaultPositionUs The default position relative to the start of the media item at * which to begin playback, in microseconds. * @return This builder. */ @@ -1471,14 +1471,14 @@ public Builder setDefaultPositionUs(long defaultPositionUs) { } /** - * Sets the duration of the playlist item, in microseconds. + * Sets the duration of the media item, in microseconds. * *

If both this duration and all {@linkplain #setPeriods period} durations are set, the sum * of this duration and the {@linkplain #setPositionInFirstPeriodUs offset in the first * period} must match the total duration of all periods. * - * @param durationUs The duration of the playlist item, in microseconds, or {@link - * C#TIME_UNSET} if unknown. + * @param durationUs The duration of the media item, in microseconds, or {@link C#TIME_UNSET} + * if unknown. * @return This builder. */ @CanIgnoreReturnValue @@ -1489,11 +1489,11 @@ public Builder setDurationUs(long durationUs) { } /** - * Sets the position of the start of this playlist item relative to the start of the first - * period belonging to it, in microseconds. + * Sets the position of the start of this media item relative to the start of the first period + * belonging to it, in microseconds. * - * @param positionInFirstPeriodUs The position of the start of this playlist item relative to - * the start of the first period belonging to it, in microseconds. + * @param positionInFirstPeriodUs The position of the start of this media item relative to the + * start of the first period belonging to it, in microseconds. * @return This builder. */ @CanIgnoreReturnValue @@ -1504,11 +1504,11 @@ public Builder setPositionInFirstPeriodUs(long positionInFirstPeriodUs) { } /** - * Sets whether this playlist item contains placeholder information because the real - * information has yet to be loaded. + * Sets whether this media item contains placeholder information because the real information + * has yet to be loaded. * - * @param isPlaceholder Whether this playlist item contains placeholder information because - * the real information has yet to be loaded. + * @param isPlaceholder Whether this media item contains placeholder information because the + * real information has yet to be loaded. * @return This builder. */ @CanIgnoreReturnValue @@ -1518,15 +1518,14 @@ public Builder setIsPlaceholder(boolean isPlaceholder) { } /** - * Sets the list of {@linkplain PeriodData periods} in this playlist item. + * Sets the list of {@linkplain PeriodData periods} in this media item. * *

All periods must have unique {@linkplain PeriodData.Builder#setUid UIDs} and only the * last period is allowed to have an unset {@linkplain PeriodData.Builder#setDurationUs * duration}. * - * @param periods The list of {@linkplain PeriodData periods} in this playlist item, or an - * empty list to assume a single period without ads and the same duration as the playlist - * item. + * @param periods The list of {@linkplain PeriodData periods} in this media item, or an empty + * list to assume a single period without ads and the same duration as the media item. * @return This builder. */ @CanIgnoreReturnValue @@ -1542,17 +1541,17 @@ public Builder setPeriods(List periods) { return this; } - /** Builds the {@link PlaylistItem}. */ - public PlaylistItem build() { - return new PlaylistItem(this); + /** Builds the {@link MediaItemData}. */ + public MediaItemData build() { + return new MediaItemData(this); } } - /** The unique identifier of this playlist item. */ + /** The unique identifier of this media item. */ public final Object uid; - /** The {@link Tracks} of this playlist item. */ + /** The {@link Tracks} of this media item. */ public final Tracks tracks; - /** The {@link MediaItem} for this playlist item. */ + /** The {@link MediaItem}. */ public final MediaItem mediaItem; /** * The {@link MediaMetadata}, including static data from the {@link MediaItem#mediaMetadata @@ -1562,9 +1561,9 @@ public PlaylistItem build() { * {@link Format#metadata Formats}. */ @Nullable public final MediaMetadata mediaMetadata; - /** The manifest of the playlist item, or null if not applicable. */ + /** The manifest of the media item, or null if not applicable. */ @Nullable public final Object manifest; - /** The active {@link MediaItem.LiveConfiguration}, or null if the playlist item is not live. */ + /** The active {@link MediaItem.LiveConfiguration}, or null if the media item is not live. */ @Nullable public final MediaItem.LiveConfiguration liveConfiguration; /** * The start time of the live presentation, in milliseconds since the Unix epoch, or {@link @@ -1582,37 +1581,37 @@ public PlaylistItem build() { * applicable. */ public final long elapsedRealtimeEpochOffsetMs; - /** Whether it's possible to seek within this playlist item. */ + /** Whether it's possible to seek within this media item. */ public final boolean isSeekable; - /** Whether this playlist item may change over time, for example a moving live window. */ + /** Whether this media item may change over time, for example a moving live window. */ public final boolean isDynamic; /** - * The default position relative to the start of the playlist item at which to begin playback, - * in microseconds. + * The default position relative to the start of the media item at which to begin playback, in + * microseconds. */ public final long defaultPositionUs; - /** The duration of the playlist item, in microseconds, or {@link C#TIME_UNSET} if unknown. */ + /** The duration of the media item, in microseconds, or {@link C#TIME_UNSET} if unknown. */ public final long durationUs; /** - * The position of the start of this playlist item relative to the start of the first period + * The position of the start of this media item relative to the start of the first period * belonging to it, in microseconds. */ public final long positionInFirstPeriodUs; /** - * Whether this playlist item contains placeholder information because the real information has - * yet to be loaded. + * Whether this media item contains placeholder information because the real information has yet + * to be loaded. */ public final boolean isPlaceholder; /** - * The list of {@linkplain PeriodData periods} in this playlist item, or an empty list to assume - * a single period without ads and the same duration as the playlist item. + * The list of {@linkplain PeriodData periods} in this media item, or an empty list to assume a + * single period without ads and the same duration as the media item. */ public final ImmutableList periods; private final long[] periodPositionInWindowUs; private final MediaMetadata combinedMediaMetadata; - private PlaylistItem(Builder builder) { + private MediaItemData(Builder builder) { if (builder.liveConfiguration == null) { checkArgument(builder.presentationStartTimeMs == C.TIME_UNSET); checkArgument(builder.windowStartTimeMs == C.TIME_UNSET); @@ -1662,26 +1661,26 @@ public boolean equals(@Nullable Object o) { if (this == o) { return true; } - if (!(o instanceof PlaylistItem)) { + if (!(o instanceof MediaItemData)) { return false; } - PlaylistItem playlistItem = (PlaylistItem) o; - return this.uid.equals(playlistItem.uid) - && this.tracks.equals(playlistItem.tracks) - && this.mediaItem.equals(playlistItem.mediaItem) - && Util.areEqual(this.mediaMetadata, playlistItem.mediaMetadata) - && Util.areEqual(this.manifest, playlistItem.manifest) - && Util.areEqual(this.liveConfiguration, playlistItem.liveConfiguration) - && this.presentationStartTimeMs == playlistItem.presentationStartTimeMs - && this.windowStartTimeMs == playlistItem.windowStartTimeMs - && this.elapsedRealtimeEpochOffsetMs == playlistItem.elapsedRealtimeEpochOffsetMs - && this.isSeekable == playlistItem.isSeekable - && this.isDynamic == playlistItem.isDynamic - && this.defaultPositionUs == playlistItem.defaultPositionUs - && this.durationUs == playlistItem.durationUs - && this.positionInFirstPeriodUs == playlistItem.positionInFirstPeriodUs - && this.isPlaceholder == playlistItem.isPlaceholder - && this.periods.equals(playlistItem.periods); + MediaItemData mediaItemData = (MediaItemData) o; + return this.uid.equals(mediaItemData.uid) + && this.tracks.equals(mediaItemData.tracks) + && this.mediaItem.equals(mediaItemData.mediaItem) + && Util.areEqual(this.mediaMetadata, mediaItemData.mediaMetadata) + && Util.areEqual(this.manifest, mediaItemData.manifest) + && Util.areEqual(this.liveConfiguration, mediaItemData.liveConfiguration) + && this.presentationStartTimeMs == mediaItemData.presentationStartTimeMs + && this.windowStartTimeMs == mediaItemData.windowStartTimeMs + && this.elapsedRealtimeEpochOffsetMs == mediaItemData.elapsedRealtimeEpochOffsetMs + && this.isSeekable == mediaItemData.isSeekable + && this.isDynamic == mediaItemData.isDynamic + && this.defaultPositionUs == mediaItemData.defaultPositionUs + && this.durationUs == mediaItemData.durationUs + && this.positionInFirstPeriodUs == mediaItemData.positionInFirstPeriodUs + && this.isPlaceholder == mediaItemData.isPlaceholder + && this.periods.equals(mediaItemData.periods); } @Override @@ -1730,7 +1729,7 @@ private Timeline.Window getWindow(int firstPeriodIndex, Timeline.Window window) } private Timeline.Period getPeriod( - int windowIndex, int periodIndexInPlaylistItem, Timeline.Period period) { + int windowIndex, int periodIndexInMediaItem, Timeline.Period period) { if (periods.isEmpty()) { period.set( /* id= */ uid, @@ -1741,7 +1740,7 @@ private Timeline.Period getPeriod( AdPlaybackState.NONE, isPlaceholder); } else { - PeriodData periodData = periods.get(periodIndexInPlaylistItem); + PeriodData periodData = periods.get(periodIndexInMediaItem); Object periodId = periodData.uid; Object periodUid = Pair.create(uid, periodId); period.set( @@ -1749,18 +1748,18 @@ private Timeline.Period getPeriod( periodUid, windowIndex, periodData.durationUs, - periodPositionInWindowUs[periodIndexInPlaylistItem], + periodPositionInWindowUs[periodIndexInMediaItem], periodData.adPlaybackState, periodData.isPlaceholder); } return period; } - private Object getPeriodUid(int periodIndexInPlaylistItem) { + private Object getPeriodUid(int periodIndexInMediaItem) { if (periods.isEmpty()) { return uid; } - Object periodId = periods.get(periodIndexInPlaylistItem).uid; + Object periodId = periods.get(periodIndexInMediaItem).uid; return Pair.create(uid, periodId); } @@ -1784,7 +1783,7 @@ private static MediaMetadata getCombinedMediaMetadata(MediaItem mediaItem, Track } } - /** Data describing the properties of a period inside a {@link PlaylistItem}. */ + /** Data describing the properties of a period inside a {@link MediaItemData}. */ protected static final class PeriodData { /** A builder for {@link PeriodData} objects. */ @@ -1798,7 +1797,7 @@ public static final class Builder { /** * Creates the builder. * - * @param uid The unique identifier of the period within its playlist item. + * @param uid The unique identifier of the period within its media item. */ public Builder(Object uid) { this.uid = uid; @@ -1815,9 +1814,9 @@ private Builder(PeriodData periodData) { } /** - * Sets the unique identifier of the period within its playlist item. + * Sets the unique identifier of the period within its media item. * - * @param uid The unique identifier of the period within its playlist item. + * @param uid The unique identifier of the period within its media item. * @return This builder. */ @CanIgnoreReturnValue @@ -1829,7 +1828,7 @@ public Builder setUid(Object uid) { /** * Sets the total duration of the period, in microseconds, or {@link C#TIME_UNSET} if unknown. * - *

Only the last period in a playlist item can have an unknown duration. + *

Only the last period in a media item can have an unknown duration. * * @param durationUs The total duration of the period, in microseconds, or {@link * C#TIME_UNSET} if unknown. @@ -1875,11 +1874,11 @@ public PeriodData build() { } } - /** The unique identifier of the period within its playlist item. */ + /** The unique identifier of the period within its media item. */ public final Object uid; /** * The total duration of the period, in microseconds, or {@link C#TIME_UNSET} if unknown. Only - * the last period in a playlist item can have an unknown duration. + * the last period in a media item can have an unknown duration. */ public final long durationUs; /** @@ -2536,8 +2535,7 @@ private void updateStateAndInformListeners(State newState) { if (timelineChanged) { @Player.TimelineChangeReason - int timelineChangeReason = - getTimelineChangeReason(previousState.playlistItems, newState.playlistItems); + int timelineChangeReason = getTimelineChangeReason(previousState.playlist, newState.playlist); listeners.queueEvent( Player.EVENT_TIMELINE_CHANGED, listener -> listener.onTimelineChanged(newState.timeline, timelineChangeReason)); @@ -2564,7 +2562,7 @@ private void updateStateAndInformListeners(State newState) { MediaItem mediaItem = state.timeline.isEmpty() ? null - : state.playlistItems.get(state.currentMediaItemIndex).mediaItem; + : state.playlist.get(state.currentMediaItemIndex).mediaItem; listeners.queueEvent( Player.EVENT_MEDIA_ITEM_TRANSITION, listener -> listener.onMediaItemTransition(mediaItem, mediaItemTransitionReason)); @@ -2792,15 +2790,15 @@ private static boolean isPlaying(State state) { } private static Tracks getCurrentTracksInternal(State state) { - return state.playlistItems.isEmpty() + return state.playlist.isEmpty() ? Tracks.EMPTY - : state.playlistItems.get(state.currentMediaItemIndex).tracks; + : state.playlist.get(state.currentMediaItemIndex).tracks; } private static MediaMetadata getMediaMetadataInternal(State state) { - return state.playlistItems.isEmpty() + return state.playlist.isEmpty() ? MediaMetadata.EMPTY - : state.playlistItems.get(state.currentMediaItemIndex).combinedMediaMetadata; + : state.playlist.get(state.currentMediaItemIndex).combinedMediaMetadata; } private static int getCurrentPeriodIndexInternal(State state, Timeline.Window window) { @@ -2814,7 +2812,7 @@ private static int getCurrentPeriodIndexInternal(State state, Timeline.Window wi } private static @Player.TimelineChangeReason int getTimelineChangeReason( - List previousPlaylist, List newPlaylist) { + List previousPlaylist, List newPlaylist) { if (previousPlaylist.size() != newPlaylist.size()) { return Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED; } @@ -2832,11 +2830,11 @@ private static int getPositionDiscontinuityReason( // We were asked to report a discontinuity. return newState.positionDiscontinuityReason; } - if (previousState.playlistItems.isEmpty()) { - // First change from an empty timeline is not reported as a discontinuity. + if (previousState.playlist.isEmpty()) { + // First change from an empty playlist is not reported as a discontinuity. return C.INDEX_UNSET; } - if (newState.playlistItems.isEmpty()) { + if (newState.playlist.isEmpty()) { // The playlist became empty. return Player.DISCONTINUITY_REASON_REMOVE; } diff --git a/libraries/common/src/test/java/androidx/media3/common/SimpleBasePlayerTest.java b/libraries/common/src/test/java/androidx/media3/common/SimpleBasePlayerTest.java index aef72f644f..d8a0e336d0 100644 --- a/libraries/common/src/test/java/androidx/media3/common/SimpleBasePlayerTest.java +++ b/libraries/common/src/test/java/androidx/media3/common/SimpleBasePlayerTest.java @@ -110,15 +110,15 @@ public void stateBuildUpon_build_isEqual() { .setTimedMetadata(new Metadata()) .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( /* adsId= */ new Object(), - /* adGroupTimesUs= */ 555, + /* adGroupTimesUs...= */ 555, 666)) .build())) .build())) @@ -142,9 +142,9 @@ public void stateBuildUpon_build_isEqual() { } @Test - public void playlistItemBuildUpon_build_isEqual() { - SimpleBasePlayer.PlaylistItem playlistItem = - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + public void mediaItemDataBuildUpon_build_isEqual() { + SimpleBasePlayer.MediaItemData mediaItemData = + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setTracks( new Tracks( ImmutableList.of( @@ -172,10 +172,10 @@ public void playlistItemBuildUpon_build_isEqual() { new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()).build())) .build(); - SimpleBasePlayer.PlaylistItem newPlaylistItem = playlistItem.buildUpon().build(); + SimpleBasePlayer.MediaItemData newMediaItemData = mediaItemData.buildUpon().build(); - assertThat(newPlaylistItem).isEqualTo(playlistItem); - assertThat(newPlaylistItem.hashCode()).isEqualTo(playlistItem.hashCode()); + assertThat(newMediaItemData).isEqualTo(mediaItemData); + assertThat(newMediaItemData.hashCode()).isEqualTo(mediaItemData.hashCode()); } @Test @@ -185,7 +185,7 @@ public void periodDataBuildUpon_build_isEqual() { .setIsPlaceholder(true) .setDurationUs(600_000) .setAdPlaybackState( - new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 555, 666)) + new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 555, 666)) .build(); SimpleBasePlayer.PeriodData newPeriodData = periodData.buildUpon().build(); @@ -220,16 +220,16 @@ public void stateBuilderBuild_setsCorrectValues() { Size surfaceSize = new Size(480, 360); DeviceInfo deviceInfo = new DeviceInfo(DeviceInfo.PLAYBACK_TYPE_LOCAL, /* minVolume= */ 3, /* maxVolume= */ 7); - ImmutableList playlist = + ImmutableList playlist = ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( - /* adsId= */ new Object(), /* adGroupTimesUs= */ 555, 666)) + /* adsId= */ new Object(), /* adGroupTimesUs...= */ 555, 666)) .build())) .build()); MediaMetadata playlistMetadata = new MediaMetadata.Builder().setArtist("artist").build(); @@ -312,7 +312,7 @@ public void stateBuilderBuild_setsCorrectValues() { assertThat(state.surfaceSize).isEqualTo(surfaceSize); assertThat(state.newlyRenderedFirstFrame).isTrue(); assertThat(state.timedMetadata).isEqualTo(timedMetadata); - assertThat(state.playlistItems).isEqualTo(playlist); + assertThat(state.playlist).isEqualTo(playlist); assertThat(state.playlistMetadata).isEqualTo(playlistMetadata); assertThat(state.currentMediaItemIndex).isEqualTo(1); assertThat(state.currentPeriodIndex).isEqualTo(1); @@ -369,8 +369,9 @@ public void stateBuilderBuild_currentWindowIndexExceedsPlaylistLength_throwsExce new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build())) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) + .build())) .setCurrentMediaItemIndex(2) .build()); } @@ -383,8 +384,9 @@ public void stateBuilderBuild_currentPeriodIndexExceedsPlaylistLength_throwsExce new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build())) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) + .build())) .setCurrentPeriodIndex(2) .build()); } @@ -397,8 +399,9 @@ public void stateBuilderBuild_currentPeriodIndexInOtherMediaItem_throwsException new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build())) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) + .build())) .setCurrentMediaItemIndex(0) .setCurrentPeriodIndex(1) .build()); @@ -412,14 +415,14 @@ public void stateBuilderBuild_currentAdGroupIndexExceedsAdGroupCount_throwsExcep new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( /* adsId= */ new Object(), - /* adGroupTimesUs= */ 123)) + /* adGroupTimesUs...= */ 123)) .build())) .build())) .setCurrentAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2) @@ -434,14 +437,14 @@ public void stateBuilderBuild_currentAdIndexExceedsAdCountInAdGroup_throwsExcept new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( /* adsId= */ new Object(), - /* adGroupTimesUs= */ 123) + /* adGroupTimesUs...= */ 123) .withAdCount( /* adGroupIndex= */ 0, /* adCount= */ 2)) .build())) @@ -466,7 +469,7 @@ public void stateBuilderBuild_playerErrorInNonIdleState_throwsException() { } @Test - public void stateBuilderBuild_multiplePlaylistItemsWithSameIds_throwsException() { + public void stateBuilderBuild_multipleMediaItemsWithSameIds_throwsException() { Object uid = new Object(); assertThrows( @@ -475,8 +478,8 @@ public void stateBuilderBuild_multiplePlaylistItemsWithSameIds_throwsException() new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(uid).build(), - new SimpleBasePlayer.PlaylistItem.Builder(uid).build())) + new SimpleBasePlayer.MediaItemData.Builder(uid).build(), + new SimpleBasePlayer.MediaItemData.Builder(uid).build())) .build()); } @@ -517,7 +520,7 @@ public void stateBuilderBuild_returnsAdvancingContentPositionWhenPlaying() { new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build())) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build())) .setContentPositionMs(4000) .setPlayWhenReady(true, Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST) .setPlaybackState(Player.STATE_READY) @@ -539,7 +542,7 @@ public void stateBuilderBuild_returnsConstantContentPositionWhenNotPlaying() { new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build())) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build())) .setContentPositionMs(4000) .setPlaybackState(Player.STATE_BUFFERING) .build(); @@ -559,14 +562,14 @@ public void stateBuilderBuild_returnsAdvancingAdPositionWhenPlaying() { new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( /* adsId= */ new Object(), - /* adGroupTimesUs= */ 123) + /* adGroupTimesUs...= */ 123) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)) .build())) .build())) @@ -593,14 +596,14 @@ public void stateBuilderBuild_returnsConstantAdPositionWhenNotPlaying() { new SimpleBasePlayer.State.Builder() .setPlaylist( ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()) .setAdPlaybackState( new AdPlaybackState( /* adsId= */ new Object(), - /* adGroupTimesUs= */ 123) + /* adGroupTimesUs...= */ 123) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)) .build())) .build())) @@ -617,7 +620,7 @@ public void stateBuilderBuild_returnsConstantAdPositionWhenNotPlaying() { } @Test - public void playlistItemBuilderBuild_setsCorrectValues() { + public void mediaItemDataBuilderBuild_setsCorrectValues() { Object uid = new Object(); Tracks tracks = new Tracks( @@ -635,8 +638,8 @@ public void playlistItemBuilderBuild_setsCorrectValues() { ImmutableList periods = ImmutableList.of(new SimpleBasePlayer.PeriodData.Builder(/* uid= */ new Object()).build()); - SimpleBasePlayer.PlaylistItem playlistItem = - new SimpleBasePlayer.PlaylistItem.Builder(uid) + SimpleBasePlayer.MediaItemData mediaItemData = + new SimpleBasePlayer.MediaItemData.Builder(uid) .setTracks(tracks) .setMediaItem(mediaItem) .setMediaMetadata(mediaMetadata) @@ -654,61 +657,61 @@ public void playlistItemBuilderBuild_setsCorrectValues() { .setPeriods(periods) .build(); - assertThat(playlistItem.uid).isEqualTo(uid); - assertThat(playlistItem.tracks).isEqualTo(tracks); - assertThat(playlistItem.mediaItem).isEqualTo(mediaItem); - assertThat(playlistItem.mediaMetadata).isEqualTo(mediaMetadata); - assertThat(playlistItem.manifest).isEqualTo(manifest); - assertThat(playlistItem.liveConfiguration).isEqualTo(liveConfiguration); - assertThat(playlistItem.presentationStartTimeMs).isEqualTo(12); - assertThat(playlistItem.windowStartTimeMs).isEqualTo(23); - assertThat(playlistItem.elapsedRealtimeEpochOffsetMs).isEqualTo(10234); - assertThat(playlistItem.isSeekable).isTrue(); - assertThat(playlistItem.isDynamic).isTrue(); - assertThat(playlistItem.defaultPositionUs).isEqualTo(456_789); - assertThat(playlistItem.durationUs).isEqualTo(500_000); - assertThat(playlistItem.positionInFirstPeriodUs).isEqualTo(100_000); - assertThat(playlistItem.isPlaceholder).isTrue(); - assertThat(playlistItem.periods).isEqualTo(periods); + assertThat(mediaItemData.uid).isEqualTo(uid); + assertThat(mediaItemData.tracks).isEqualTo(tracks); + assertThat(mediaItemData.mediaItem).isEqualTo(mediaItem); + assertThat(mediaItemData.mediaMetadata).isEqualTo(mediaMetadata); + assertThat(mediaItemData.manifest).isEqualTo(manifest); + assertThat(mediaItemData.liveConfiguration).isEqualTo(liveConfiguration); + assertThat(mediaItemData.presentationStartTimeMs).isEqualTo(12); + assertThat(mediaItemData.windowStartTimeMs).isEqualTo(23); + assertThat(mediaItemData.elapsedRealtimeEpochOffsetMs).isEqualTo(10234); + assertThat(mediaItemData.isSeekable).isTrue(); + assertThat(mediaItemData.isDynamic).isTrue(); + assertThat(mediaItemData.defaultPositionUs).isEqualTo(456_789); + assertThat(mediaItemData.durationUs).isEqualTo(500_000); + assertThat(mediaItemData.positionInFirstPeriodUs).isEqualTo(100_000); + assertThat(mediaItemData.isPlaceholder).isTrue(); + assertThat(mediaItemData.periods).isEqualTo(periods); } @Test - public void playlistItemBuilderBuild_presentationStartTimeIfNotLive_throwsException() { + public void mediaItemDataBuilderBuild_presentationStartTimeIfNotLive_throwsException() { assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPresentationStartTimeMs(12) .build()); } @Test - public void playlistItemBuilderBuild_windowStartTimeIfNotLive_throwsException() { + public void mediaItemDataBuilderBuild_windowStartTimeIfNotLive_throwsException() { assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setWindowStartTimeMs(12) .build()); } @Test - public void playlistItemBuilderBuild_elapsedEpochOffsetIfNotLive_throwsException() { + public void mediaItemDataBuilderBuild_elapsedEpochOffsetIfNotLive_throwsException() { assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setElapsedRealtimeEpochOffsetMs(12) .build()); } @Test public void - playlistItemBuilderBuild_windowStartTimeLessThanPresentationStartTime_throwsException() { + mediaItemDataBuilderBuild_windowStartTimeLessThanPresentationStartTime_throwsException() { assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setLiveConfiguration(MediaItem.LiveConfiguration.UNSET) .setWindowStartTimeMs(12) .setPresentationStartTimeMs(13) @@ -716,13 +719,13 @@ public void playlistItemBuilderBuild_elapsedEpochOffsetIfNotLive_throwsException } @Test - public void playlistItemBuilderBuild_multiplePeriodsWithSameUid_throwsException() { + public void mediaItemDataBuilderBuild_multiplePeriodsWithSameUid_throwsException() { Object uid = new Object(); assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setPeriods( ImmutableList.of( new SimpleBasePlayer.PeriodData.Builder(uid).build(), @@ -731,11 +734,11 @@ public void playlistItemBuilderBuild_multiplePeriodsWithSameUid_throwsException( } @Test - public void playlistItemBuilderBuild_defaultPositionGreaterThanDuration_throwsException() { + public void mediaItemDataBuilderBuild_defaultPositionGreaterThanDuration_throwsException() { assertThrows( IllegalArgumentException.class, () -> - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setDefaultPositionUs(16) .setDurationUs(15) .build()); @@ -745,7 +748,7 @@ public void playlistItemBuilderBuild_defaultPositionGreaterThanDuration_throwsEx public void periodDataBuilderBuild_setsCorrectValues() { Object uid = new Object(); AdPlaybackState adPlaybackState = - new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 555, 666); + new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 555, 666); SimpleBasePlayer.PeriodData periodData = new SimpleBasePlayer.PeriodData.Builder(uid) @@ -788,7 +791,7 @@ public void getterMethods_noOtherMethodCalls_returnCurrentState() { SimpleBasePlayer.PositionSupplier contentPositionSupplier = () -> 456; SimpleBasePlayer.PositionSupplier contentBufferedPositionSupplier = () -> 499; SimpleBasePlayer.PositionSupplier totalBufferedPositionSupplier = () -> 567; - Object playlistItemUid = new Object(); + Object mediaItemUid = new Object(); Object periodUid = new Object(); Tracks tracks = new Tracks( @@ -804,10 +807,10 @@ public void getterMethods_noOtherMethodCalls_returnCurrentState() { Size surfaceSize = new Size(480, 360); MediaItem.LiveConfiguration liveConfiguration = new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(2000).build(); - ImmutableList playlist = + ImmutableList playlist = ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(playlistItemUid) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid) .setTracks(tracks) .setMediaItem(mediaItem) .setMediaMetadata(mediaMetadata) @@ -829,7 +832,7 @@ public void getterMethods_noOtherMethodCalls_returnCurrentState() { .setDurationUs(600_000) .setAdPlaybackState( new AdPlaybackState( - /* adsId= */ new Object(), /* adGroupTimesUs= */ 555, 666)) + /* adsId= */ new Object(), /* adGroupTimesUs...= */ 555, 666)) .build())) .build()); State state = @@ -948,7 +951,7 @@ protected State getState() { assertThat(window.liveConfiguration).isEqualTo(liveConfiguration); assertThat(window.manifest).isEqualTo(manifest); assertThat(window.mediaItem).isEqualTo(mediaItem); - assertThat(window.uid).isEqualTo(playlistItemUid); + assertThat(window.uid).isEqualTo(mediaItemUid); Timeline.Period period = timeline.getPeriod(/* periodIndex= */ 0, new Timeline.Period(), /* setIds= */ true); assertThat(period.durationUs).isEqualTo(C.TIME_UNSET); @@ -974,10 +977,10 @@ public void getterMethods_duringAd_returnAdState() { SimpleBasePlayer.PositionSupplier totalBufferedPositionSupplier = () -> 567; SimpleBasePlayer.PositionSupplier adPositionSupplier = () -> 321; SimpleBasePlayer.PositionSupplier adBufferedPositionSupplier = () -> 345; - ImmutableList playlist = + ImmutableList playlist = ImmutableList.of( - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(), - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()) + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(), + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()) .setDurationUs(500_000) .setPeriods( ImmutableList.of( @@ -986,7 +989,9 @@ public void getterMethods_duringAd_returnAdState() { .setDurationUs(600_000) .setAdPlaybackState( new AdPlaybackState( - /* adsId= */ new Object(), /* adGroupTimesUs= */ 555, 666) + /* adsId= */ new Object(), /* adGroupTimesUs...= */ + 555, + 666) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1) .withAdDurationsUs( @@ -1051,8 +1056,8 @@ protected State getState() { public void invalidateState_updatesStateAndInformsListeners() throws Exception { Object mediaItemUid0 = new Object(); MediaItem mediaItem0 = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem0 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid0).setMediaItem(mediaItem0).build(); + SimpleBasePlayer.MediaItemData mediaItemData0 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid0).setMediaItem(mediaItem0).build(); State state1 = new State.Builder() .setAvailableCommands(new Commands.Builder().addAllCommands().build()) @@ -1078,7 +1083,7 @@ public void invalidateState_updatesStateAndInformsListeners() throws Exception { .setDeviceInfo(DeviceInfo.UNKNOWN) .setDeviceVolume(0) .setIsDeviceMuted(false) - .setPlaylist(ImmutableList.of(playlistItem0)) + .setPlaylist(ImmutableList.of(mediaItemData0)) .setPlaylistMetadata(MediaMetadata.EMPTY) .setCurrentMediaItemIndex(0) .setContentPositionMs(8_000) @@ -1094,8 +1099,8 @@ public void invalidateState_updatesStateAndInformsListeners() throws Exception { /* adaptiveSupported= */ true, /* trackSupport= */ new int[] {C.FORMAT_HANDLED}, /* trackSelected= */ new boolean[] {true}))); - SimpleBasePlayer.PlaylistItem playlistItem1 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1) + SimpleBasePlayer.MediaItemData mediaItemData1 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1) .setMediaItem(mediaItem1) .setMediaMetadata(mediaMetadata) .setTracks(tracks) @@ -1156,7 +1161,7 @@ public void invalidateState_updatesStateAndInformsListeners() throws Exception { .setSurfaceSize(surfaceSize) .setNewlyRenderedFirstFrame(true) .setTimedMetadata(timedMetadata) - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setPlaylistMetadata(playlistMetadata) .setCurrentMediaItemIndex(1) .setContentPositionMs(12_000) @@ -1297,20 +1302,20 @@ protected State getState() { } @Test - public void invalidateState_withPlaylistItemDetailChange_reportsTimelineSourceUpdate() { + public void invalidateState_withMediaItemDetailChange_reportsTimelineSourceUpdate() { Object mediaItemUid0 = new Object(); - SimpleBasePlayer.PlaylistItem playlistItem0 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid0).build(); + SimpleBasePlayer.MediaItemData mediaItemData0 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid0).build(); Object mediaItemUid1 = new Object(); - SimpleBasePlayer.PlaylistItem playlistItem1 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1).build(); + SimpleBasePlayer.MediaItemData mediaItemData1 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1).build(); State state1 = - new State.Builder().setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)).build(); - SimpleBasePlayer.PlaylistItem playlistItem1Updated = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1).setDurationUs(10_000).build(); + new State.Builder().setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)).build(); + SimpleBasePlayer.MediaItemData mediaItemData1Updated = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1).setDurationUs(10_000).build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1Updated)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1Updated)) .build(); AtomicBoolean returnState2 = new AtomicBoolean(); SimpleBasePlayer player = @@ -1336,21 +1341,21 @@ protected State getState() { public void invalidateState_withCurrentMediaItemRemoval_reportsDiscontinuityReasonRemoved() { Object mediaItemUid0 = new Object(); MediaItem mediaItem0 = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem0 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid0).setMediaItem(mediaItem0).build(); + SimpleBasePlayer.MediaItemData mediaItemData0 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid0).setMediaItem(mediaItem0).build(); Object mediaItemUid1 = new Object(); MediaItem mediaItem1 = new MediaItem.Builder().setMediaId("1").build(); - SimpleBasePlayer.PlaylistItem playlistItem1 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); + SimpleBasePlayer.MediaItemData mediaItemData1 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setCurrentMediaItemIndex(1) .setContentPositionMs(5000) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0)) + .setPlaylist(ImmutableList.of(mediaItemData0)) .setCurrentMediaItemIndex(0) .setContentPositionMs(2000) .build(); @@ -1402,24 +1407,24 @@ protected State getState() { invalidateState_withTransitionFromEndOfItem_reportsDiscontinuityReasonAutoTransition() { Object mediaItemUid0 = new Object(); MediaItem mediaItem0 = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem0 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid0) + SimpleBasePlayer.MediaItemData mediaItemData0 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid0) .setMediaItem(mediaItem0) .setDurationUs(50_000) .build(); Object mediaItemUid1 = new Object(); MediaItem mediaItem1 = new MediaItem.Builder().setMediaId("1").build(); - SimpleBasePlayer.PlaylistItem playlistItem1 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); + SimpleBasePlayer.MediaItemData mediaItemData1 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setCurrentMediaItemIndex(0) .setContentPositionMs(50) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setCurrentMediaItemIndex(1) .setContentPositionMs(10) .build(); @@ -1469,24 +1474,24 @@ protected State getState() { public void invalidateState_withTransitionFromMiddleOfItem_reportsDiscontinuityReasonSkip() { Object mediaItemUid0 = new Object(); MediaItem mediaItem0 = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem0 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid0) + SimpleBasePlayer.MediaItemData mediaItemData0 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid0) .setMediaItem(mediaItem0) .setDurationUs(50_000) .build(); Object mediaItemUid1 = new Object(); MediaItem mediaItem1 = new MediaItem.Builder().setMediaId("1").build(); - SimpleBasePlayer.PlaylistItem playlistItem1 = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); + SimpleBasePlayer.MediaItemData mediaItemData1 = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid1).setMediaItem(mediaItem1).build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setCurrentMediaItemIndex(0) .setContentPositionMs(20) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem0, playlistItem1)) + .setPlaylist(ImmutableList.of(mediaItemData0, mediaItemData1)) .setCurrentMediaItemIndex(1) .setContentPositionMs(10) .build(); @@ -1537,20 +1542,20 @@ protected State getState() { public void invalidateState_withRepeatingItem_reportsDiscontinuityReasonAutoTransition() { Object mediaItemUid = new Object(); MediaItem mediaItem = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid) + SimpleBasePlayer.MediaItemData mediaItemData = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid) .setMediaItem(mediaItem) .setDurationUs(5_000_000) .build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(5_000) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(0) .build(); @@ -1600,20 +1605,20 @@ protected State getState() { public void invalidateState_withDiscontinuityInsideItem_reportsDiscontinuityReasonInternal() { Object mediaItemUid = new Object(); MediaItem mediaItem = new MediaItem.Builder().setMediaId("0").build(); - SimpleBasePlayer.PlaylistItem playlistItem = - new SimpleBasePlayer.PlaylistItem.Builder(mediaItemUid) + SimpleBasePlayer.MediaItemData mediaItemData = + new SimpleBasePlayer.MediaItemData.Builder(mediaItemUid) .setMediaItem(mediaItem) .setDurationUs(5_000_000) .build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(1_000) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(3_000) .build(); @@ -1661,17 +1666,17 @@ protected State getState() { @Test public void invalidateState_withMinorPositionDrift_doesNotReportsDiscontinuity() { - SimpleBasePlayer.PlaylistItem playlistItem = - new SimpleBasePlayer.PlaylistItem.Builder(/* uid= */ new Object()).build(); + SimpleBasePlayer.MediaItemData mediaItemData = + new SimpleBasePlayer.MediaItemData.Builder(/* uid= */ new Object()).build(); State state1 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(1_000) .build(); State state2 = new State.Builder() - .setPlaylist(ImmutableList.of(playlistItem)) + .setPlaylist(ImmutableList.of(mediaItemData)) .setCurrentMediaItemIndex(0) .setContentPositionMs(1_500) .build();