From 50b2d82b086d52981cf3e660d4e804b444d4246f Mon Sep 17 00:00:00 2001 From: Colin Kho Date: Fri, 8 Nov 2024 10:32:53 -0800 Subject: [PATCH] Added getter methods to ContainerMediaChunk & a callback method whenever a load loop is finished --- .../source/chunk/ContainerMediaChunk.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk.java index b2dff4d01ec..c9164134ad6 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk.java @@ -135,6 +135,7 @@ public final void load() throws IOException { nextLoadPosition = input.getPosition() - dataSpec.position; } } finally { + onLoadIterationEnded(); DataSourceUtil.closeQuietly(dataSource); } loadCompleted = !loadCanceled; @@ -151,6 +152,30 @@ protected TrackOutputProvider getTrackOutputProvider(BaseMediaChunkOutput baseMe return baseMediaChunkOutput; } + /** + * Method that is called to signal that a {@link #load()} has concluded. This is called in both + * successful and error scenarios. + */ + protected void onLoadIterationEnded() {} + + /** + * Returns whether the current chunk's load has been canceled from {@link #cancelLoad()} + * + * @return true if {@link #cancelLoad()} was invoked + */ + public final boolean isLoadCanceled() { + return loadCanceled; + } + + /** + * Retrieves the next position to load in the chunk on a {@link #load()} + * + * @return the position to load from + */ + public final long getNextLoadPosition() { + return nextLoadPosition; + } + private void maybeWriteEmptySamples(BaseMediaChunkOutput output) { if (!MimeTypes.isImage(trackFormat.containerMimeType)) { return;