mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make DynamicConcatenatingMediaSource reusable.
Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183648419
This commit is contained in:
parent
1f6d161d4d
commit
72d99284c1
3 changed files with 28 additions and 3 deletions
|
|
@ -333,7 +333,6 @@ public final class DynamicConcatenatingMediaSource extends CompositeMediaSource<
|
||||||
public synchronized void prepareSource(ExoPlayer player, boolean isTopLevelSource,
|
public synchronized void prepareSource(ExoPlayer player, boolean isTopLevelSource,
|
||||||
Listener listener) {
|
Listener listener) {
|
||||||
super.prepareSource(player, isTopLevelSource, listener);
|
super.prepareSource(player, isTopLevelSource, listener);
|
||||||
Assertions.checkState(this.listener == null, MEDIA_SOURCE_REUSED_ERROR_MESSAGE);
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
preventListenerNotification = true;
|
preventListenerNotification = true;
|
||||||
|
|
@ -372,6 +371,17 @@ public final class DynamicConcatenatingMediaSource extends CompositeMediaSource<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void releaseSource() {
|
||||||
|
super.releaseSource();
|
||||||
|
mediaSourceHolders.clear();
|
||||||
|
player = null;
|
||||||
|
listener = null;
|
||||||
|
shuffleOrder = shuffleOrder.cloneAndClear();
|
||||||
|
windowCount = 0;
|
||||||
|
periodCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onChildSourceInfoRefreshed(
|
protected void onChildSourceInfoRefreshed(
|
||||||
MediaSourceHolder mediaSourceHolder,
|
MediaSourceHolder mediaSourceHolder,
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,11 @@ public interface ShuffleOrder {
|
||||||
return new DefaultShuffleOrder(newShuffled, new Random(random.nextLong()));
|
return new DefaultShuffleOrder(newShuffled, new Random(random.nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShuffleOrder cloneAndClear() {
|
||||||
|
return new DefaultShuffleOrder(/* length= */ 0, new Random(random.nextLong()));
|
||||||
|
}
|
||||||
|
|
||||||
private static int[] createShuffledList(int length, Random random) {
|
private static int[] createShuffledList(int length, Random random) {
|
||||||
int[] shuffled = new int[length];
|
int[] shuffled = new int[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
|
@ -199,6 +204,10 @@ public interface ShuffleOrder {
|
||||||
return new UnshuffledShuffleOrder(length - 1);
|
return new UnshuffledShuffleOrder(length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShuffleOrder cloneAndClear() {
|
||||||
|
return new UnshuffledShuffleOrder(/* length= */ 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -237,7 +246,7 @@ public interface ShuffleOrder {
|
||||||
int getFirstIndex();
|
int getFirstIndex();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a copy of the shuffle order with newly inserted elements.
|
* Returns a copy of the shuffle order with newly inserted elements.
|
||||||
*
|
*
|
||||||
* @param insertionIndex The index in the unshuffled order at which elements are inserted.
|
* @param insertionIndex The index in the unshuffled order at which elements are inserted.
|
||||||
* @param insertionCount The number of elements inserted at {@code insertionIndex}.
|
* @param insertionCount The number of elements inserted at {@code insertionIndex}.
|
||||||
|
|
@ -246,11 +255,13 @@ public interface ShuffleOrder {
|
||||||
ShuffleOrder cloneAndInsert(int insertionIndex, int insertionCount);
|
ShuffleOrder cloneAndInsert(int insertionIndex, int insertionCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a copy of the shuffle order with one element removed.
|
* Returns a copy of the shuffle order with one element removed.
|
||||||
*
|
*
|
||||||
* @param removalIndex The index of the element in the unshuffled order which is to be removed.
|
* @param removalIndex The index of the element in the unshuffled order which is to be removed.
|
||||||
* @return A copy of this {@link ShuffleOrder} without the removed element.
|
* @return A copy of this {@link ShuffleOrder} without the removed element.
|
||||||
*/
|
*/
|
||||||
ShuffleOrder cloneAndRemove(int removalIndex);
|
ShuffleOrder cloneAndRemove(int removalIndex);
|
||||||
|
|
||||||
|
/** Returns a copy of the shuffle order with all elements removed. */
|
||||||
|
ShuffleOrder cloneAndClear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,4 +65,8 @@ public final class FakeShuffleOrder implements ShuffleOrder {
|
||||||
return new FakeShuffleOrder(length - 1);
|
return new FakeShuffleOrder(length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShuffleOrder cloneAndClear() {
|
||||||
|
return new FakeShuffleOrder(/* length= */ 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue