From 1cc1bf02eff8b8dd198664a3c6d090716bbf694e Mon Sep 17 00:00:00 2001 From: Colin Kho Date: Wed, 31 Jul 2024 22:35:39 -0700 Subject: [PATCH] Added onLoadStarted callback to Loader's callback --- .../media3/exoplayer/upstream/Loader.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/upstream/Loader.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/upstream/Loader.java index 8fc3ffecb3..18fda8598d 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/upstream/Loader.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/upstream/Loader.java @@ -90,6 +90,18 @@ public final class Loader implements LoaderErrorThrower { /** A callback to be notified of {@link Loader} events. */ public interface Callback { + /** + * Called when a load has started for the first time or through a retry. + * + * @param loadable The loadable whose load has completed. + * @param elapsedRealtimeMs {@link SystemClock#elapsedRealtime} when the load ended. + * @param loadDurationMs The duration in milliseconds of the load since {@link #startLoading} + * was called. + * @param error The load error of the previous load attempt if this is a retry, otherwise null + * @param errorCount The number of errors this load has encountered thus far. + */ + default void onLoadStarted(T loadable, long elapsedRealtimeMs, long loadDurationMs, @Nullable IOException error, int errorCount) {} + /** * Called when a load has completed. * @@ -531,6 +543,9 @@ public final class Loader implements LoaderErrorThrower { } private void execute() { + long nowMs = SystemClock.elapsedRealtime(); + long durationMs = nowMs - startTimeMs; + Assertions.checkNotNull(this.callback).onLoadStarted(loadable, nowMs, durationMs, currentError, errorCount); currentError = null; downloadExecutor.execute(Assertions.checkNotNull(currentTask)); }