Commit 72d99284 by tonihei Committed by Oliver Woodman

Make DynamicConcatenatingMediaSource reusable.

Issue:#3498

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183648419
parent 1f6d161d
......@@ -333,7 +333,6 @@ public final class DynamicConcatenatingMediaSource extends CompositeMediaSource<
public synchronized void prepareSource(ExoPlayer player, boolean isTopLevelSource,
Listener listener) {
super.prepareSource(player, isTopLevelSource, listener);
Assertions.checkState(this.listener == null, MEDIA_SOURCE_REUSED_ERROR_MESSAGE);
this.player = player;
this.listener = listener;
preventListenerNotification = true;
......@@ -373,6 +372,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
protected void onChildSourceInfoRefreshed(
MediaSourceHolder mediaSourceHolder,
MediaSource mediaSource,
......
......@@ -136,6 +136,11 @@ public interface ShuffleOrder {
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) {
int[] shuffled = new int[length];
for (int i = 0; i < length; i++) {
......@@ -199,6 +204,10 @@ public interface ShuffleOrder {
return new UnshuffledShuffleOrder(length - 1);
}
@Override
public ShuffleOrder cloneAndClear() {
return new UnshuffledShuffleOrder(/* length= */ 0);
}
}
/**
......@@ -237,7 +246,7 @@ public interface ShuffleOrder {
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 insertionCount The number of elements inserted at {@code insertionIndex}.
......@@ -246,11 +255,13 @@ public interface ShuffleOrder {
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.
* @return A copy of this {@link ShuffleOrder} without the removed element.
*/
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);
}
@Override
public ShuffleOrder cloneAndClear() {
return new FakeShuffleOrder(/* length= */ 0);
}
}
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