mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Implement addMediaItems(List) and clearMediaItems() in BasePlayer
PiperOrigin-RevId: 361487730
This commit is contained in:
parent
c1dba81ed2
commit
ffb7c466ed
6 changed files with 20 additions and 47 deletions
|
|
@ -316,11 +316,6 @@ public final class CastPlayer extends BasePlayer {
|
||||||
toMediaQueueItems(mediaItems), startWindowIndex, startPositionMs, repeatMode.value);
|
toMediaQueueItems(mediaItems), startWindowIndex, startPositionMs, repeatMode.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMediaItems(List<MediaItem> mediaItems) {
|
|
||||||
addMediaItemsInternal(toMediaQueueItems(mediaItems), MediaQueueItem.INVALID_ITEM_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
||||||
Assertions.checkArgument(index >= 0);
|
Assertions.checkArgument(index >= 0);
|
||||||
|
|
@ -353,8 +348,8 @@ public final class CastPlayer extends BasePlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMediaItems(int fromIndex, int toIndex) {
|
public void removeMediaItems(int fromIndex, int toIndex) {
|
||||||
Assertions.checkArgument(
|
Assertions.checkArgument(fromIndex >= 0 && toIndex >= fromIndex);
|
||||||
fromIndex >= 0 && toIndex >= fromIndex && toIndex <= currentTimeline.getWindowCount());
|
toIndex = min(toIndex, currentTimeline.getWindowCount());
|
||||||
if (fromIndex == toIndex) {
|
if (fromIndex == toIndex) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
return;
|
return;
|
||||||
|
|
@ -366,11 +361,6 @@ public final class CastPlayer extends BasePlayer {
|
||||||
removeMediaItemsInternal(uids);
|
removeMediaItemsInternal(uids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearMediaItems() {
|
|
||||||
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ currentTimeline.getWindowCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommandAvailable(@Command int command) {
|
public boolean isCommandAvailable(@Command int command) {
|
||||||
return availableCommands.contains(command);
|
return availableCommands.contains(command);
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,11 @@ public abstract class BasePlayer implements Player {
|
||||||
addMediaItems(Collections.singletonList(mediaItem));
|
addMediaItems(Collections.singletonList(mediaItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void addMediaItems(List<MediaItem> mediaItems) {
|
||||||
|
addMediaItems(/* index= */ Integer.MAX_VALUE, mediaItems);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void moveMediaItem(int currentIndex, int newIndex) {
|
public final void moveMediaItem(int currentIndex, int newIndex) {
|
||||||
if (currentIndex != newIndex) {
|
if (currentIndex != newIndex) {
|
||||||
|
|
@ -71,6 +76,11 @@ public abstract class BasePlayer implements Player {
|
||||||
removeMediaItems(/* fromIndex= */ index, /* toIndex= */ index + 1);
|
removeMediaItems(/* fromIndex= */ index, /* toIndex= */ index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void clearMediaItems() {
|
||||||
|
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void play() {
|
public final void play() {
|
||||||
setPlayWhenReady(true);
|
setPlayWhenReady(true);
|
||||||
|
|
|
||||||
|
|
@ -1153,7 +1153,8 @@ public interface Player {
|
||||||
/**
|
/**
|
||||||
* Adds a media item at the given index of the playlist.
|
* 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.
|
* @param mediaItem The {@link MediaItem} to add.
|
||||||
*/
|
*/
|
||||||
void addMediaItem(int index, MediaItem mediaItem);
|
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.
|
* 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.
|
* @param mediaItems The {@link MediaItem MediaItems} to add.
|
||||||
*/
|
*/
|
||||||
void addMediaItems(int index, List<MediaItem> mediaItems);
|
void addMediaItems(int index, List<MediaItem> mediaItems);
|
||||||
|
|
@ -1204,7 +1206,8 @@ public interface Player {
|
||||||
* Removes a range of media items from the playlist.
|
* Removes a range of media items from the playlist.
|
||||||
*
|
*
|
||||||
* @param fromIndex The index at which to start removing media items.
|
* @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);
|
void removeMediaItems(int fromIndex, int toIndex);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -415,13 +415,9 @@ import java.util.List;
|
||||||
mediaSources, startWindowIndex, startPositionMs, /* resetToDefaultPosition= */ false);
|
mediaSources, startWindowIndex, startPositionMs, /* resetToDefaultPosition= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMediaItems(List<MediaItem> mediaItems) {
|
|
||||||
addMediaItems(/* index= */ mediaSourceHolderSnapshots.size(), mediaItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
||||||
|
index = min(index, mediaSourceHolderSnapshots.size());
|
||||||
addMediaSources(index, createMediaSources(mediaItems));
|
addMediaSources(index, createMediaSources(mediaItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -464,6 +460,7 @@ import java.util.List;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMediaItems(int fromIndex, int toIndex) {
|
public void removeMediaItems(int fromIndex, int toIndex) {
|
||||||
|
toIndex = min(toIndex, mediaSourceHolderSnapshots.size());
|
||||||
PlaybackInfo playbackInfo = removeMediaItemsInternal(fromIndex, toIndex);
|
PlaybackInfo playbackInfo = removeMediaItemsInternal(fromIndex, toIndex);
|
||||||
updatePlaybackInfo(
|
updatePlaybackInfo(
|
||||||
playbackInfo,
|
playbackInfo,
|
||||||
|
|
@ -501,11 +498,6 @@ import java.util.List;
|
||||||
/* seekProcessed= */ false);
|
/* seekProcessed= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearMediaItems() {
|
|
||||||
removeMediaItems(/* fromIndex= */ 0, /* toIndex= */ mediaSourceHolderSnapshots.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
|
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
|
||||||
Timeline timeline = createMaskingTimeline();
|
Timeline timeline = createMaskingTimeline();
|
||||||
|
|
|
||||||
|
|
@ -1357,12 +1357,6 @@ public class SimpleExoPlayer extends BasePlayer
|
||||||
player.setMediaSource(mediaSource, startPositionMs);
|
player.setMediaSource(mediaSource, startPositionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMediaItems(List<MediaItem> mediaItems) {
|
|
||||||
verifyApplicationThread();
|
|
||||||
player.addMediaItems(mediaItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
|
|
@ -1405,12 +1399,6 @@ public class SimpleExoPlayer extends BasePlayer
|
||||||
player.removeMediaItems(fromIndex, toIndex);
|
player.removeMediaItems(fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearMediaItems() {
|
|
||||||
verifyApplicationThread();
|
|
||||||
player.clearMediaItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
|
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
|
|
|
||||||
|
|
@ -192,11 +192,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMediaItems(List<MediaItem> mediaItems) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
public void addMediaItems(int index, List<MediaItem> mediaItems) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
@ -232,11 +227,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearMediaItems() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommandAvailable(int command) {
|
public boolean isCommandAvailable(int command) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue