Skip to content

Commit ca51ed6

Browse files
toniheicopybara-github
authored andcommitted
Fix single sample handling ProgressiveMediaPeriod when disabling tracks
When deselecting the single sample track and later re-selecting this track, the current shortcuts in ProgressiveMediaPeriod don't handle this case correctly and cause assertion failures. In particular, this change fixes 3 issues: 1. When re-selecting the single sample track, we have cleared the SampleQueue and need to reload the sample. The existing shortcut should only be applied to avoid the reload when starting from a non-zero position. 2. When de-selecting the track, ProgressiveMediaPeriod is left in an inconsistent state where the sample queues are empty but loadingFinished is still true. Fix this by resetting loadingFinished to false. 3. When seeking, we avoid reloading the stream if we can keep inside the existing samples. This logic assumes that all remaining samples will continue to be loaded in the queue. This condition isn't true though for single sample tracks that have been de-selected. They appear to support the seek inside the queue (=no seek necessary, always supported), but still require a new load if there is no ongoing one to load the sample. Fix this by checking this implicit assumption (still loading, or loading finished). PiperOrigin-RevId: 642650248
1 parent 94dff1f commit ca51ed6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ public long selectTracks(
276276
streams[i] = null;
277277
}
278278
}
279-
// We'll always need to seek if this is a first selection to a non-zero position, or if we're
280-
// making a selection having previously disabled all tracks, except for when we have a single
281-
// sample.
279+
// We'll always need to seek if this is a first selection to a non-zero position (except for
280+
// when we have a single sample only), or if we're making a selection having previously
281+
// disabled all tracks.
282282
boolean seekRequired =
283-
!isSingleSample && (seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != 0);
283+
seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != 0 && !isSingleSample;
284284
// Select new tracks.
285285
for (int i = 0; i < selections.length; i++) {
286286
if (streams[i] == null && selections[i] != null) {
@@ -315,6 +315,7 @@ public long selectTracks(
315315
}
316316
loader.cancelLoading();
317317
} else {
318+
loadingFinished = false;
318319
for (SampleQueue sampleQueue : sampleQueues) {
319320
sampleQueue.reset();
320321
}
@@ -434,8 +435,10 @@ public long seekToUs(long positionUs) {
434435
return positionUs;
435436
}
436437

437-
// If we're not playing a live stream, try and seek within the buffer.
438+
// If we're not playing a live stream, and when loading will continue (or has finished), try
439+
// and seek within the existing buffer instead of restarting the load.
438440
if (dataType != C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
441+
&& (loadingFinished || loader.isLoading())
439442
&& seekInsideBufferUs(trackIsAudioVideoFlags, positionUs)) {
440443
return positionUs;
441444
}

0 commit comments

Comments
 (0)