diff --git a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
index 039d6dd810..85f365e51e 100644
--- a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
+++ b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
@@ -1264,11 +1264,14 @@ import java.io.IOException;
sampleStreams, streamResetFlags, positionUs);
periodTrackSelections = trackSelections;
+ // Update whether we have enabled tracks and sanity check the expected streams are non-null.
hasEnabledTracks = false;
for (int i = 0; i < sampleStreams.length; i++) {
if (sampleStreams[i] != null) {
+ Assertions.checkState(trackSelections.get(i) != null);
hasEnabledTracks = true;
- break;
+ } else {
+ Assertions.checkState(trackSelections.get(i) == null);
}
}
diff --git a/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java
index 227dc29366..81721d587c 100644
--- a/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java
+++ b/library/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java
@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.trackselection.TrackSelection;
+import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.IdentityHashMap;
@@ -103,10 +104,17 @@ import java.util.IdentityHashMap;
boolean periodEnabled = false;
for (int j = 0; j < selections.length; j++) {
if (selectionChildIndices[j] == i) {
+ // Assert that the child provided a stream for the selection.
+ Assertions.checkState(childStreams[j] != null);
streams[j] = childStreams[j];
- if (childStreams[j] != null) {
- periodEnabled = true;
- streamPeriodIndices.put(childStreams[j], i);
+ periodEnabled = true;
+ streamPeriodIndices.put(childStreams[j], i);
+ } else if (streamChildIndices[j] == i) {
+ // Assert that the child cleared any previous stream.
+ Assertions.checkState(childStreams[j] == null);
+ if (selectionChildIndices[j] == C.INDEX_UNSET) {
+ // No other child will be setting the stream at index j, so clear it.
+ streams[j] = null;
}
}
}
@@ -133,19 +141,20 @@ import java.util.IdentityHashMap;
@Override
public long readDiscontinuity() {
- long positionUs = enabledPeriods[0].readDiscontinuity();
- if (positionUs != C.TIME_UNSET) {
- // It must be possible to seek additional periods to the new position.
- for (int i = 1; i < enabledPeriods.length; i++) {
- if (enabledPeriods[i].seekToUs(positionUs) != positionUs) {
- throw new IllegalStateException("Children seeked to different positions");
- }
+ long positionUs = periods[0].readDiscontinuity();
+ // Periods other than the first one are not allowed to report discontinuities.
+ for (int i = 1; i < periods.length; i++) {
+ if (periods[i].readDiscontinuity() != C.TIME_UNSET) {
+ throw new IllegalStateException("Child reported discontinuity");
}
}
- // Additional periods are not allowed to report discontinuities.
- for (int i = 1; i < enabledPeriods.length; i++) {
- if (enabledPeriods[i].readDiscontinuity() != C.TIME_UNSET) {
- throw new IllegalStateException("Child reported discontinuity");
+ // It must be possible to seek enabled periods to the new position, if there is one.
+ if (positionUs != C.TIME_UNSET) {
+ for (int i = 0; i < enabledPeriods.length; i++) {
+ if (enabledPeriods[i] != periods[0]
+ && enabledPeriods[i].seekToUs(positionUs) != positionUs) {
+ throw new IllegalStateException("Children seeked to different positions");
+ }
}
}
return positionUs;
diff --git a/library/src/main/res/layout/exo_simple_player_view.xml b/library/src/main/res/layout/exo_simple_player_view.xml
index e1745abcff..99945b8d25 100644
--- a/library/src/main/res/layout/exo_simple_player_view.xml
+++ b/library/src/main/res/layout/exo_simple_player_view.xml
@@ -22,17 +22,17 @@
android:layout_height="match_parent"
android:layout_gravity="center">
+
+
-
-