Commit 4297800f by tonihei Committed by Oliver Woodman

Update logic to set isLoading.

We currently set it to shouldContinueLoading, which isn't correct if
shouldContinueLoading is set to false and we still have an ongoing load.

Change it to also be true if the media period is still loading.

PiperOrigin-RevId: 272823473
parent 69cf7d13
......@@ -113,6 +113,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private boolean released;
private boolean playWhenReady;
private boolean rebuffering;
private boolean shouldContinueLoading;
@Player.RepeatMode private int repeatMode;
private boolean shuffleModeEnabled;
private boolean foregroundMode;
......@@ -415,12 +416,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
}
private void setIsLoading(boolean isLoading) {
if (playbackInfo.isLoading != isLoading) {
playbackInfo = playbackInfo.copyWithIsLoading(isLoading);
}
}
private void maybeNotifyPlaybackInfoChanged() {
if (playbackInfoUpdate.hasPendingUpdate(playbackInfo)) {
eventHandler
......@@ -921,7 +916,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
queue.clear(/* keepFrontPeriodUid= */ !resetState);
setIsLoading(false);
shouldContinueLoading = false;
if (resetState) {
queue.setTimeline(Timeline.EMPTY);
for (PendingMessageInfo pendingMessageInfo : pendingMessages) {
......@@ -1546,17 +1541,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
info,
emptyTrackSelectorResult);
mediaPeriodHolder.mediaPeriod.prepare(this, info.startPositionUs);
setIsLoading(true);
if (queue.getPlayingPeriod() == mediaPeriodHolder) {
resetRendererPosition(mediaPeriodHolder.getStartPositionRendererTime());
}
handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
}
}
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
if (loadingPeriodHolder == null || loadingPeriodHolder.isFullyBuffered()) {
setIsLoading(false);
} else if (!playbackInfo.isLoading) {
if (shouldContinueLoading) {
shouldContinueLoading = isLoadingPossible();
updateIsLoading();
} else {
maybeContinueLoading();
}
}
......@@ -1757,20 +1751,41 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
private void maybeContinueLoading() {
shouldContinueLoading = shouldContinueLoading();
if (shouldContinueLoading) {
queue.getLoadingPeriod().continueLoading(rendererPositionUs);
}
updateIsLoading();
}
private boolean shouldContinueLoading() {
if (!isLoadingPossible()) {
return false;
}
long bufferedDurationUs =
getTotalBufferedDurationUs(queue.getLoadingPeriod().getNextLoadPositionUs());
float playbackSpeed = mediaClock.getPlaybackParameters().speed;
return loadControl.shouldContinueLoading(bufferedDurationUs, playbackSpeed);
}
private boolean isLoadingPossible() {
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
if (loadingPeriodHolder == null) {
return false;
}
long nextLoadPositionUs = loadingPeriodHolder.getNextLoadPositionUs();
if (nextLoadPositionUs == C.TIME_END_OF_SOURCE) {
setIsLoading(false);
return;
return false;
}
long bufferedDurationUs =
getTotalBufferedDurationUs(/* bufferedPositionInLoadingPeriodUs= */ nextLoadPositionUs);
boolean continueLoading =
loadControl.shouldContinueLoading(
bufferedDurationUs, mediaClock.getPlaybackParameters().speed);
setIsLoading(continueLoading);
if (continueLoading) {
loadingPeriodHolder.continueLoading(rendererPositionUs);
return true;
}
private void updateIsLoading() {
MediaPeriodHolder loadingPeriod = queue.getLoadingPeriod();
boolean isLoading =
shouldContinueLoading || (loadingPeriod != null && loadingPeriod.mediaPeriod.isLoading());
if (isLoading != playbackInfo.isLoading) {
playbackInfo = playbackInfo.copyWithIsLoading(isLoading);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment