Propagate playback position through LoadControl shouldContinueLoading.

PiperOrigin-RevId: 304420177
This commit is contained in:
olly 2020-04-02 17:50:33 +01:00 committed by Oliver Woodman
parent 6438e1cdbc
commit fb0330d4db
3 changed files with 25 additions and 3 deletions

View File

@ -3,6 +3,7 @@
### dev-v2 (not yet released) ###
* Core library:
* Add playbackPositionUs parameter to 'LoadControl.shouldContinueLoading'.
* The `DefaultLoadControl` default minimum buffer is set to 50 seconds,
equal to the default maximum buffer. `DefaultLoadControl` applies the
same behavior for audio and video.

View File

@ -1945,9 +1945,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
if (!isLoadingPossible()) {
return false;
}
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
long bufferedDurationUs =
getTotalBufferedDurationUs(queue.getLoadingPeriod().getNextLoadPositionUs());
return loadControl.shouldContinueLoading(bufferedDurationUs, mediaClock.getPlaybackSpeed());
getTotalBufferedDurationUs(loadingPeriodHolder.getNextLoadPositionUs());
long playbackPositionUs =
loadingPeriodHolder == queue.getPlayingPeriod()
? loadingPeriodHolder.toPeriodTime(rendererPositionUs)
: loadingPeriodHolder.toPeriodTime(rendererPositionUs)
- loadingPeriodHolder.info.startPositionUs;
return loadControl.shouldContinueLoading(
playbackPositionUs, bufferedDurationUs, mediaClock.getPlaybackSpeed());
}
private boolean isLoadingPossible() {

View File

@ -87,14 +87,28 @@ public interface LoadControl {
*/
boolean retainBackBufferFromKeyframe();
/** @deprecated Use {@link LoadControl#shouldContinueLoading(long, long, float)}. */
@Deprecated
default boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
return false;
}
/**
* Called by the player to determine whether it should continue to load the source.
*
* @param playbackPositionUs The current playback position in microseconds, relative to the start
* of the {@link Timeline.Period period} that will continue to be loaded if this method
* returns {@code true}. If the playback for this period has not yet started, the value will
* negative and equal in magnitude to the duration of any media in previous periods still to
* be played.
* @param bufferedDurationUs The duration of media that's currently buffered.
* @param playbackSpeed The current playback speed.
* @return Whether the loading should continue.
*/
boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed);
default boolean shouldContinueLoading(
long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
return shouldContinueLoading(bufferedDurationUs, playbackSpeed);
}
/**
* Called repeatedly by the player when it's loading the source, has yet to start playback, and