diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5715869155..bbc47722b8 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 19c69f9aa0..d217bb1848 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -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() { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java b/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java index 80be0b9e71..d91830a5aa 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/LoadControl.java @@ -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