From 23f316d67e2cb2f89ed2fb6a05264c6573436384 Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 23 Jan 2020 14:04:21 +0000 Subject: [PATCH] Always keep front period uid in MediaPeriodQueue. Since we have the Playlist layer on top, it's always guaranteed that a new playlist item has a new uid. So we can just keep the old one in all cases and don't have to be careful to delete it. The deletion was necessary previously in case multiple MediaSources use the same uids. PiperOrigin-RevId: 291152349 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 4 ++-- .../google/android/exoplayer2/MediaPeriodQueue.java | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 4643779e68..194fd89083 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -1014,7 +1014,7 @@ import java.util.concurrent.atomic.AtomicBoolean; maybeContinueLoading(); } else { // New period has not been prepared. - queue.clear(/* keepFrontPeriodUid= */ true); + queue.clear(); resetRendererPosition(periodPositionUs); } @@ -1139,7 +1139,7 @@ import java.util.concurrent.atomic.AtomicBoolean; } } - queue.clear(/* keepFrontPeriodUid= */ !clearPlaylist); + queue.clear(); shouldContinueLoading = false; Timeline timeline = playbackInfo.timeline; if (clearPlaylist) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java b/library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java index 50a71d7970..f72e83adb5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java @@ -256,21 +256,14 @@ import com.google.android.exoplayer2.util.Assertions; return removedReading; } - /** - * Clears the queue. - * - * @param keepFrontPeriodUid Whether the queue should keep the id of the media period in the front - * of queue (typically the playing one) for later reuse. - */ - public void clear(boolean keepFrontPeriodUid) { + /** Clears the queue. */ + public void clear() { MediaPeriodHolder front = playing; if (front != null) { - oldFrontPeriodUid = keepFrontPeriodUid ? front.uid : null; + oldFrontPeriodUid = front.uid; oldFrontPeriodWindowSequenceNumber = front.info.id.windowSequenceNumber; removeAfter(front); front.release(); - } else if (!keepFrontPeriodUid) { - oldFrontPeriodUid = null; } playing = null; loading = null;