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();