Commit ffb7c466 by gyumin Committed by Ian Baker

Implement addMediaItems(List) and clearMediaItems() in BasePlayer

PiperOrigin-RevId: 361487730
parent c1dba81e
......@@ -317,11 +317,6 @@ public final class CastPlayer extends BasePlayer {
}
@Override
public void addMediaItems(List<MediaItem> mediaItems) {
addMediaItemsInternal(toMediaQueueItems(mediaItems), MediaQueueItem.INVALID_ITEM_ID);
}
@Override
public void addMediaItems(int index, List<MediaItem> mediaItems) {
Assertions.checkArgument(index >= 0);
int uid = MediaQueueItem.INVALID_ITEM_ID;
......@@ -353,8 +348,8 @@ public final class CastPlayer extends BasePlayer {
@Override
public void removeMediaItems(int fromIndex, int toIndex) {
Assertions.checkArgument(
fromIndex >= 0 && toIndex >= fromIndex && toIndex <= currentTimeline.getWindowCount());
Assertions.checkArgument(fromIndex >= 0 && toIndex >= fromIndex);
toIndex = min(toIndex, currentTimeline.getWindowCount());
if (fromIndex == toIndex) {
// Do nothing.
return;
......@@ -367,11 +362,6 @@ public final class CastPlayer extends BasePlayer {
}
@Override
public void clearMediaItems() {
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ currentTimeline.getWindowCount());
}
@Override
public boolean isCommandAvailable(@Command int command) {
return availableCommands.contains(command);
}
......
......@@ -60,6 +60,11 @@ public abstract class BasePlayer implements Player {
}
@Override
public final void addMediaItems(List<MediaItem> mediaItems) {
addMediaItems(/* index= */ Integer.MAX_VALUE, mediaItems);
}
@Override
public final void moveMediaItem(int currentIndex, int newIndex) {
if (currentIndex != newIndex) {
moveMediaItems(/* fromIndex= */ currentIndex, /* toIndex= */ currentIndex + 1, newIndex);
......@@ -72,6 +77,11 @@ public abstract class BasePlayer implements Player {
}
@Override
public final void clearMediaItems() {
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE);
}
@Override
public final void play() {
setPlayWhenReady(true);
}
......
......@@ -1153,7 +1153,8 @@ public interface Player {
/**
* Adds a media item at the given index of the playlist.
*
* @param index The index at which to add the item.
* @param index The index at which to add the media item. If the index is larger than the size of
* the playlist, the media item is added to the end of the playlist.
* @param mediaItem The {@link MediaItem} to add.
*/
void addMediaItem(int index, MediaItem mediaItem);
......@@ -1168,7 +1169,8 @@ public interface Player {
/**
* Adds a list of media items at the given index of the playlist.
*
* @param index The index at which to add the media items.
* @param index The index at which to add the media items. If the index is larger than the size of
* the playlist, the media items are added to the end of the playlist.
* @param mediaItems The {@link MediaItem MediaItems} to add.
*/
void addMediaItems(int index, List<MediaItem> mediaItems);
......@@ -1204,7 +1206,8 @@ public interface Player {
* Removes a range of media items from the playlist.
*
* @param fromIndex The index at which to start removing media items.
* @param toIndex The index of the first item to be kept (exclusive).
* @param toIndex The index of the first item to be kept (exclusive). If the index is larger than
* the size of the playlist, media items to the end of the playlist are removed.
*/
void removeMediaItems(int fromIndex, int toIndex);
......
......@@ -416,12 +416,8 @@ import java.util.List;
}
@Override
public void addMediaItems(List<MediaItem> mediaItems) {
addMediaItems(/* index= */ mediaSourceHolderSnapshots.size(), mediaItems);
}
@Override
public void addMediaItems(int index, List<MediaItem> mediaItems) {
index = min(index, mediaSourceHolderSnapshots.size());
addMediaSources(index, createMediaSources(mediaItems));
}
......@@ -464,6 +460,7 @@ import java.util.List;
@Override
public void removeMediaItems(int fromIndex, int toIndex) {
toIndex = min(toIndex, mediaSourceHolderSnapshots.size());
PlaybackInfo playbackInfo = removeMediaItemsInternal(fromIndex, toIndex);
updatePlaybackInfo(
playbackInfo,
......@@ -502,11 +499,6 @@ import java.util.List;
}
@Override
public void clearMediaItems() {
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ mediaSourceHolderSnapshots.size());
}
@Override
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
Timeline timeline = createMaskingTimeline();
PlaybackInfo newPlaybackInfo =
......
......@@ -1358,12 +1358,6 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
public void addMediaItems(List<MediaItem> mediaItems) {
verifyApplicationThread();
player.addMediaItems(mediaItems);
}
@Override
public void addMediaItems(int index, List<MediaItem> mediaItems) {
verifyApplicationThread();
player.addMediaItems(index, mediaItems);
......@@ -1406,12 +1400,6 @@ public class SimpleExoPlayer extends BasePlayer
}
@Override
public void clearMediaItems() {
verifyApplicationThread();
player.clearMediaItems();
}
@Override
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
verifyApplicationThread();
player.setShuffleOrder(shuffleOrder);
......
......@@ -193,11 +193,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public void addMediaItems(List<MediaItem> mediaItems) {
throw new UnsupportedOperationException();
}
@Override
public void addMediaItems(int index, List<MediaItem> mediaItems) {
throw new UnsupportedOperationException();
}
......@@ -233,11 +228,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public void clearMediaItems() {
throw new UnsupportedOperationException();
}
@Override
public boolean isCommandAvailable(int command) {
throw new UnsupportedOperationException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment