From e03623f7012cd25075fd90d01dad4504fac684cf Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 20 Jul 2018 03:25:11 -0700 Subject: [PATCH] Fix issue with keeping window sequence number after repeated seeks. The number is shelved in calls to queue.clear() to keep it for the next media period. However, the queue may also become empty by repeated calls to advancePlayingPeriod which may happen when seeking to an unprepared period. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=205376036 --- .../android/exoplayer2/MediaPeriodQueue.java | 4 +- .../android/exoplayer2/ExoPlayerTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 717f873622..17a8ddd8d4 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 @@ -228,11 +228,13 @@ import com.google.android.exoplayer2.util.Assertions; reading = playing.next; } playing.release(); - playing = playing.next; length--; if (length == 0) { loading = null; + oldFrontPeriodUid = playing.uid; + oldFrontPeriodWindowSequenceNumber = playing.info.id.windowSequenceNumber; } + playing = playing.next; } else { playing = loading; reading = loading; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java index c05f8914f5..559a915b2b 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java @@ -1980,6 +1980,44 @@ public final class ExoPlayerTest { .inOrder(); } + @Test + public void testRepeatedSeeksToUnpreparedPeriodInSameWindowKeepsWindowSequenceNumber() + throws Exception { + Timeline timeline = + new FakeTimeline( + new TimelineWindowDefinition( + /* periodCount= */ 2, + /* id= */ 0, + /* isSeekable= */ true, + /* isDynamic= */ false, + /* durationUs= */ 10 * C.MICROS_PER_SECOND)); + FakeMediaSource mediaSource = new FakeMediaSource(timeline, /* manifest= */ null); + ActionSchedule actionSchedule = + new ActionSchedule.Builder("testSeekToUnpreparedPeriod") + .pause() + .waitForPlaybackState(Player.STATE_READY) + .seek(/* windowIndex= */ 0, /* positionMs= */ 9999) + .seek(/* windowIndex= */ 0, /* positionMs= */ 1) + .seek(/* windowIndex= */ 0, /* positionMs= */ 9999) + .play() + .build(); + ExoPlayerTestRunner testRunner = + new ExoPlayerTestRunner.Builder() + .setMediaSource(mediaSource) + .setActionSchedule(actionSchedule) + .build() + .start() + .blockUntilEnded(TIMEOUT_MS); + + testRunner.assertPlayedPeriodIndices(0, 1, 0, 1); + assertThat(mediaSource.getCreatedMediaPeriods()) + .containsAllOf( + new MediaPeriodId(/* periodIndex= */ 0, /* windowSequenceNumber= */ 0), + new MediaPeriodId(/* periodIndex= */ 1, /* windowSequenceNumber= */ 0)); + assertThat(mediaSource.getCreatedMediaPeriods()) + .doesNotContain(new MediaPeriodId(/* periodIndex= */ 1, /* windowSequenceNumber= */ 1)); + } + @Test public void testRecursivePlayerChangesReportConsistentValuesForAllListeners() throws Exception { // We add two listeners to the player. The first stops the player as soon as it's ready and both