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; ...@@ -113,6 +113,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private boolean released; private boolean released;
private boolean playWhenReady; private boolean playWhenReady;
private boolean rebuffering; private boolean rebuffering;
private boolean shouldContinueLoading;
@Player.RepeatMode private int repeatMode; @Player.RepeatMode private int repeatMode;
private boolean shuffleModeEnabled; private boolean shuffleModeEnabled;
private boolean foregroundMode; private boolean foregroundMode;
...@@ -415,12 +416,6 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -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() { private void maybeNotifyPlaybackInfoChanged() {
if (playbackInfoUpdate.hasPendingUpdate(playbackInfo)) { if (playbackInfoUpdate.hasPendingUpdate(playbackInfo)) {
eventHandler eventHandler
...@@ -921,7 +916,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -921,7 +916,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
queue.clear(/* keepFrontPeriodUid= */ !resetState); queue.clear(/* keepFrontPeriodUid= */ !resetState);
setIsLoading(false); shouldContinueLoading = false;
if (resetState) { if (resetState) {
queue.setTimeline(Timeline.EMPTY); queue.setTimeline(Timeline.EMPTY);
for (PendingMessageInfo pendingMessageInfo : pendingMessages) { for (PendingMessageInfo pendingMessageInfo : pendingMessages) {
...@@ -1546,17 +1541,16 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -1546,17 +1541,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
info, info,
emptyTrackSelectorResult); emptyTrackSelectorResult);
mediaPeriodHolder.mediaPeriod.prepare(this, info.startPositionUs); mediaPeriodHolder.mediaPeriod.prepare(this, info.startPositionUs);
setIsLoading(true);
if (queue.getPlayingPeriod() == mediaPeriodHolder) { if (queue.getPlayingPeriod() == mediaPeriodHolder) {
resetRendererPosition(mediaPeriodHolder.getStartPositionRendererTime()); resetRendererPosition(mediaPeriodHolder.getStartPositionRendererTime());
} }
handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false); handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false);
} }
} }
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod(); if (shouldContinueLoading) {
if (loadingPeriodHolder == null || loadingPeriodHolder.isFullyBuffered()) { shouldContinueLoading = isLoadingPossible();
setIsLoading(false); updateIsLoading();
} else if (!playbackInfo.isLoading) { } else {
maybeContinueLoading(); maybeContinueLoading();
} }
} }
...@@ -1757,20 +1751,41 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -1757,20 +1751,41 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
private void maybeContinueLoading() { 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(); MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
if (loadingPeriodHolder == null) {
return false;
}
long nextLoadPositionUs = loadingPeriodHolder.getNextLoadPositionUs(); long nextLoadPositionUs = loadingPeriodHolder.getNextLoadPositionUs();
if (nextLoadPositionUs == C.TIME_END_OF_SOURCE) { if (nextLoadPositionUs == C.TIME_END_OF_SOURCE) {
setIsLoading(false); return false;
return;
} }
long bufferedDurationUs = return true;
getTotalBufferedDurationUs(/* bufferedPositionInLoadingPeriodUs= */ nextLoadPositionUs); }
boolean continueLoading =
loadControl.shouldContinueLoading( private void updateIsLoading() {
bufferedDurationUs, mediaClock.getPlaybackParameters().speed); MediaPeriodHolder loadingPeriod = queue.getLoadingPeriod();
setIsLoading(continueLoading); boolean isLoading =
if (continueLoading) { shouldContinueLoading || (loadingPeriod != null && loadingPeriod.mediaPeriod.isLoading());
loadingPeriodHolder.continueLoading(rendererPositionUs); 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