From 3fbfc0ec0e6f5685fa712777339fb4e3317bef00 Mon Sep 17 00:00:00 2001 From: gyumin Date: Tue, 23 Mar 2021 09:26:54 +0000 Subject: [PATCH] Fix Timeline.toBundle for empty timeline PiperOrigin-RevId: 364513299 --- .../main/java/com/google/android/exoplayer2/Timeline.java | 4 +++- .../java/com/google/android/exoplayer2/TimelineTest.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java b/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java index 627d999c4c..6682a33959 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java @@ -1291,7 +1291,9 @@ public abstract class Timeline implements Bundleable { } int[] shuffledWindowIndices = new int[windowCount]; - shuffledWindowIndices[0] = getFirstWindowIndex(/* shuffleModeEnabled= */ true); + if (windowCount > 0) { + shuffledWindowIndices[0] = getFirstWindowIndex(/* shuffleModeEnabled= */ true); + } for (int i = 1; i < windowCount; i++) { shuffledWindowIndices[i] = getNextWindowIndex( diff --git a/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java b/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java index f442baa493..beaf2eec36 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java @@ -278,6 +278,11 @@ public class TimelineTest { timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ true); } + @Test + public void roundtripViaBundle_ofEmptyTimeline_returnsEmptyTimeline() { + TimelineAsserts.assertEmpty(Timeline.CREATOR.fromBundle(Timeline.EMPTY.toBundle())); + } + @Test public void roundtripViaBundle_ofWindow_yieldsEqualInstanceExceptUidAndManifest() { Timeline.Window window = new Timeline.Window();