Add missing check before calling discardBuffer

The method is only allowed to be called on prepared items.
This check was currently missing and also causing the
corresponding test to be flaky in ExoPlayerTest.

PiperOrigin-RevId: 634694077
This commit is contained in:
tonihei 2024-05-17 03:07:33 -07:00 committed by Copybara-Service
parent 282a944eb4
commit 2b5bb945e1

View File

@ -2585,15 +2585,15 @@ import java.util.concurrent.atomic.AtomicBoolean;
playbackPositionUs,
bufferedDurationUs,
mediaClock.getPlaybackParameters().speed);
MediaPeriodHolder playingPeriodHolder = queue.getPlayingPeriod();
if (!shouldContinueLoading
&& playingPeriodHolder.prepared
&& bufferedDurationUs < PLAYBACK_BUFFER_EMPTY_THRESHOLD_US
&& (backBufferDurationUs > 0 || retainBackBufferFromKeyframe)) {
// LoadControl doesn't want to continue loading despite no buffered data. Clear back buffer
// and try again in case it's blocked on memory usage of the back buffer.
queue
.getPlayingPeriod()
.mediaPeriod
.discardBuffer(playbackInfo.positionUs, /* toKeyframe= */ false);
playingPeriodHolder.mediaPeriod.discardBuffer(
playbackInfo.positionUs, /* toKeyframe= */ false);
shouldContinueLoading =
loadControl.shouldContinueLoading(
playerId,