mirror of
https://github.com/samsonjs/media.git
synced 2026-04-08 11:45:51 +00:00
Merge pull request #4564 from BrainCrumbz/feat/playlist-remove-range
feat(playlist): remove MediaSource range
This commit is contained in:
commit
52b6b3b8e0
1 changed files with 78 additions and 5 deletions
|
|
@ -49,10 +49,11 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||
private static final int MSG_ADD = 0;
|
||||
private static final int MSG_ADD_MULTIPLE = 1;
|
||||
private static final int MSG_REMOVE = 2;
|
||||
private static final int MSG_MOVE = 3;
|
||||
private static final int MSG_CLEAR = 4;
|
||||
private static final int MSG_NOTIFY_LISTENER = 5;
|
||||
private static final int MSG_ON_COMPLETION = 6;
|
||||
private static final int MSG_REMOVE_RANGE = 3;
|
||||
private static final int MSG_MOVE = 4;
|
||||
private static final int MSG_CLEAR = 5;
|
||||
private static final int MSG_NOTIFY_LISTENER = 6;
|
||||
private static final int MSG_ON_COMPLETION = 7;
|
||||
|
||||
// Accessed on the app thread.
|
||||
private final List<MediaSourceHolder> mediaSourcesPublic;
|
||||
|
|
@ -264,6 +265,9 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||
* <p>Note: If you want to move the instance, it's preferable to use {@link #moveMediaSource(int,
|
||||
* int)} instead.
|
||||
*
|
||||
* <p>Note: If you want to remove a set of contiguous sources, it's preferable to use
|
||||
* {@link #removeMediaSourceRange(int, int)} instead.
|
||||
*
|
||||
* @param index The index at which the media source will be removed. This index must be in the
|
||||
* range of 0 <= index < {@link #getSize()}.
|
||||
*/
|
||||
|
|
@ -275,7 +279,10 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||
* Removes a {@link MediaSource} from the playlist and executes a custom action on completion.
|
||||
*
|
||||
* <p>Note: If you want to move the instance, it's preferable to use {@link #moveMediaSource(int,
|
||||
* int)} instead.
|
||||
* int, Runnable)} instead.
|
||||
*
|
||||
* <p>Note: If you want to remove a set of contiguous sources, it's preferable to use
|
||||
* {@link #removeMediaSourceRange(int, int, Runnable)} instead.
|
||||
*
|
||||
* @param index The index at which the media source will be removed. This index must be in the
|
||||
* range of 0 <= index < {@link #getSize()}.
|
||||
|
|
@ -296,6 +303,60 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a range of {@link MediaSource}s from the playlist, by specifying an initial index
|
||||
* (included) and a final index (excluded).
|
||||
*
|
||||
* <p>Note: when specified range is empty, no actual media source is removed and no exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param fromIndex The initial range index, pointing to the first media source that will be
|
||||
* removed. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
||||
* @param toIndex The final range index, pointing to the first media source that will be left
|
||||
* untouched. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
||||
* @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} <
|
||||
* 0, {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex}
|
||||
*/
|
||||
public final synchronized void removeMediaSourceRange(int fromIndex, int toIndex) {
|
||||
removeMediaSourceRange(fromIndex, toIndex, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a range of {@link MediaSource}s from the playlist, by specifying an initial index
|
||||
* (included) and a final index (excluded), and executes a custom action on completion.
|
||||
*
|
||||
* <p>Note: when specified range is empty, no actual media source is removed and no exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param fromIndex The initial range index, pointing to the first media source that will be
|
||||
* removed. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
||||
* @param toIndex The final range index, pointing to the first media source that will be left
|
||||
* untouched. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
||||
* @param actionOnCompletion A {@link Runnable} which is executed immediately after the media
|
||||
* source range has been removed from the playlist.
|
||||
* @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} <
|
||||
* 0, {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex}
|
||||
*/
|
||||
public final synchronized void removeMediaSourceRange(
|
||||
int fromIndex, int toIndex, @Nullable Runnable actionOnCompletion) {
|
||||
Util.removeRange(mediaSourcesPublic, fromIndex, toIndex);
|
||||
if (fromIndex == toIndex) {
|
||||
if (actionOnCompletion != null) {
|
||||
actionOnCompletion.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (player != null) {
|
||||
player
|
||||
.createMessage(this)
|
||||
.setType(MSG_REMOVE_RANGE)
|
||||
.setPayload(new MessageData<>(fromIndex, toIndex, actionOnCompletion))
|
||||
.send();
|
||||
} else if (actionOnCompletion != null) {
|
||||
actionOnCompletion.run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an existing {@link MediaSource} within the playlist.
|
||||
*
|
||||
|
|
@ -487,6 +548,18 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||
removeMediaSourceInternal(removeMessage.index);
|
||||
scheduleListenerNotification(removeMessage.actionOnCompletion);
|
||||
break;
|
||||
case MSG_REMOVE_RANGE:
|
||||
MessageData<Integer> removeRangeMessage = (MessageData<Integer>) message;
|
||||
int fromIndex = removeRangeMessage.index;
|
||||
int toIndex = removeRangeMessage.customData;
|
||||
for (int index = toIndex - 1; index >= fromIndex; index--) {
|
||||
shuffleOrder = shuffleOrder.cloneAndRemove(index);
|
||||
}
|
||||
for (int index = toIndex - 1; index >= fromIndex; index--) {
|
||||
removeMediaSourceInternal(index);
|
||||
}
|
||||
scheduleListenerNotification(removeRangeMessage.actionOnCompletion);
|
||||
break;
|
||||
case MSG_MOVE:
|
||||
MessageData<Integer> moveMessage = (MessageData<Integer>) message;
|
||||
shuffleOrder = shuffleOrder.cloneAndRemove(moveMessage.index);
|
||||
|
|
|
|||
Loading…
Reference in a new issue