# ChunkSampleStream

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/source/chunk/ChunkSampleStream.java+class:androidx.media3.exoplayer.source.chunk.ChunkSampleStream)

*** ** * ** ***


```
@UnstableApi
public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, SequenceableLoader, Loader.Callback<Chunk>, Loader.ReleaseCallback
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream` that loads media in `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk`s, obtained from a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSource`. May also be configured to expose additional embedded `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream`s.

## Summary

| ### Nested types |
|---|
| `public final inner class https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream implements https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream` A `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream` embedded in a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream`. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.ReleaseCallback<T extends https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSource>` A callback to be notified when a sample stream has finished being released. |

| ### Public fields |
|---|---|
| `final T` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#chunkSource()` |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.TrackType https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#primaryTrackType()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#ChunkSampleStream(int,int[],androidx.media3.common.Format[],T,androidx.media3.exoplayer.source.SequenceableLoader.Callback<androidx.media3.exoplayer.source.chunk.ChunkSampleStream<T>>,androidx.media3.exoplayer.upstream.Allocator,long,androidx.media3.exoplayer.drm.DrmSessionManager,androidx.media3.exoplayer.drm.DrmSessionEventListener.EventDispatcher,androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy,androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher,boolean,long,androidx.media3.exoplayer.util.ReleasableExecutor)( @https://developer.android.com/reference/androidx/media3/common/C.TrackType int primaryTrackType, @https://developer.android.com/reference/androidx/annotation/Nullable int[] embeddedTrackTypes, @https://developer.android.com/reference/androidx/annotation/Nullable Format[] embeddedTrackFormats, T chunkSource, https://developer.android.com/reference/androidx/media3/exoplayer/source/SequenceableLoader.Callback<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream<T>> callback, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator allocator, long positionUs, https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager drmSessionManager, https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher drmEventDispatcher, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy loadErrorHandlingPolicy, https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, boolean handleInitialDiscontinuity, long firstChunkStartTimeUs, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor downloadExecutor )` Constructs an instance. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()()` Consumes a pending initial discontinuity. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#continueLoading(androidx.media3.exoplayer.LoadingInfo)(https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo loadingInfo)` Attempts to continue loading. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#discardBuffer(long,boolean)(long positionUs, boolean toKeyframe)` Discards buffered media up to the specified position. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#discardUpstreamSamplesForClippedDuration(long)(long clippedDurationUs)` Discards upstream samples that exceed the given clipped duration of the stream. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#getAdjustedSeekPositionUs(long,androidx.media3.exoplayer.SeekParameters)( long positionUs, https://developer.android.com/reference/androidx/media3/exoplayer/SeekParameters seekParameters )` Adjusts a seek position given the specified `https://developer.android.com/reference/androidx/media3/exoplayer/SeekParameters`. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#getBufferedPositionUs()()` Returns an estimate of the position up to which data is buffered. |
| `T` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#getChunkSource()()` Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSource` used by this stream. |
| `int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.Flags https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#getFlags()()` Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.Flags` set on this stream. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#getNextLoadPositionUs()()` Returns the next load time, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` if loading has finished. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#isLoading()()` Returns whether the loader is currently loading. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#isReady()()` Returns whether data is available to be read. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#mayHaveInitialDiscontinuity()()` Returns whether there could be a pending initial discontinuity that needs to be consumed by `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#maybeThrowError()()` Throws an error that's preventing data from being read. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#onLoadCanceled(androidx.media3.exoplayer.source.chunk.Chunk,long,long,boolean)( https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released )` Called when a load has been canceled. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#onLoadCompleted(androidx.media3.exoplayer.source.chunk.Chunk,long,long)( https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable, long elapsedRealtimeMs, long loadDurationMs )` Called when a load has completed. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.LoadErrorAction` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#onLoadError(androidx.media3.exoplayer.source.chunk.Chunk,long,long,java.io.IOException,int)( https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, https://developer.android.com/reference/java/io/IOException.html error, int errorCount )` Called when a load encounters an error. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#onLoadStarted(androidx.media3.exoplayer.source.chunk.Chunk,long,long,int)( https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, int retryCount )` Called when a load has started for the first time or through a retry. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#onLoaderReleased()()` Called when the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` has finished being released. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)( https://developer.android.com/reference/androidx/media3/exoplayer/FormatHolder formatHolder, https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer buffer, @https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.ReadFlags int readFlags )` Attempts to read from the stream. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#reevaluateBuffer(long)(long positionUs)` Re-evaluates the buffer given the playback position. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#release()()` Releases the stream. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#release(androidx.media3.exoplayer.source.chunk.ChunkSampleStream.ReleaseCallback<T>)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.ReleaseCallback<T> callback)` Releases the stream. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#seekToUs(long)(long positionUs)` Seeks to the specified position in microseconds. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#selectEmbeddedTrack(long,int)(long positionUs, int trackType)` Selects the embedded track, returning a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` from which the track's samples can be consumed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#setEndPositionUs(long)(long endPositionUs)` Sets the end position at which the period stops loading and providing samples. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#setSuppressRead(boolean)(boolean suppressRead)` Sets whether to suppress any read operation from the stream. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#setUsesStreamPrerollFlags()()` Sets whether `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#mayHaveInitialDiscontinuity()` should block on a pending initial discontinuity that has not yet been consumed by `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()`. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#skipData(long)(long positionUs)` Attempts to skip to the keyframe before the specified position, or to the end of the stream if `positionUs` is beyond it. |

### Inherited Constants

From [androidx.media3.exoplayer.source.SampleStream](https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream) `static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_HAS_PREROLL() = 4`

Specifies that the stream contains a preroll of decode-only samples.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_MAYBE_HAS_PREROLL() = 2`

Specifies that the stream may contain preroll samples.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_OMIT_SAMPLE_DATA() = 4`

Specifies that `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()`, `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` and `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#cryptoInfo()` should not be populated when reading a sample buffer.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_PEEK() = 1`

Specifies that the read position should not be advanced if a sample buffer is read.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_REQUIRE_FORMAT() = 2`

Specifies that if a sample buffer would normally be read next, the format of the stream should be read instead.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#FLAG_STRICT_DURATION() = 1`

Specifies that playout of the stream should be stopped once the duration is reached.

## Public fields

### chunkSource

```
public final T chunkSource
```

### primaryTrackType

```
@C.TrackType
public final int primaryTrackType
```

## Public constructors

### ChunkSampleStream

```
public ChunkSampleStream(
    @C.TrackType int primaryTrackType,
    @Nullable int[] embeddedTrackTypes,
    @Nullable Format[] embeddedTrackFormats,
    T chunkSource,
    SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
    Allocator allocator,
    long positionUs,
    DrmSessionManager drmSessionManager,
    DrmSessionEventListener.EventDispatcher drmEventDispatcher,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher,
    boolean handleInitialDiscontinuity,
    long firstChunkStartTimeUs,
    @Nullable ReleasableExecutor downloadExecutor
)
```

Constructs an instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.TrackType int primaryTrackType` | The `https://developer.android.com/reference/androidx/media3/common/C.TrackType` of the primary track. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable int[] embeddedTrackTypes` | The types of any embedded tracks, or null. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable Format[] embeddedTrackFormats` | The formats of the embedded tracks, or null. |
| `T chunkSource` | A `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSource` from which chunks to load are obtained. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/SequenceableLoader.Callback<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream<T>> callback` | An `https://developer.android.com/reference/androidx/media3/exoplayer/source/SequenceableLoader.Callback` for the stream. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator allocator` | An `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Allocator` from which allocations can be obtained. |
| `long positionUs` | The position from which to start loading media. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager drmSessionManager` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionManager` to obtain `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSession` from. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher drmEventDispatcher` | A dispatcher to notify of `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmSessionEventListener` events. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy loadErrorHandlingPolicy` | The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher` | A dispatcher to notify of `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSourceEventListener` events. |
| `boolean handleInitialDiscontinuity` | Whether the stream needs to handle an initial discontinuity if the first chunk can't start at the beginning and needs to preroll data. |
| `long firstChunkStartTimeUs` | The start time of the first chunk in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not known yet. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor downloadExecutor` | An optional externally provided `https://developer.android.com/reference/androidx/media3/exoplayer/util/ReleasableExecutor` for loading and extracting media. |

## Public methods

### consumeInitialDiscontinuity

```
public boolean consumeInitialDiscontinuity()
```

Consumes a pending initial discontinuity.

| Returns |
|---|---|
| `boolean` | Whether the stream had an initial discontinuity. |

### continueLoading

```
public boolean continueLoading(LoadingInfo loadingInfo)
```

Attempts to continue loading.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo loadingInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo` when attempting to continue loading. |

| Returns |
|---|---|
| `boolean` | True if progress was made, meaning that `https://developer.android.com/reference/androidx/media3/exoplayer/source/SequenceableLoader#getNextLoadPositionUs()` will return a different value than prior to the call. False otherwise. |

### discardBuffer

```
public void discardBuffer(long positionUs, boolean toKeyframe)
```

Discards buffered media up to the specified position.

| Parameters |
|---|---|
| `long positionUs` | The position to discard up to, in microseconds. |
| `boolean toKeyframe` | If true then for each track discards samples up to the keyframe before or at the specified position, rather than any sample before or at that position. |

### discardUpstreamSamplesForClippedDuration

```
public void discardUpstreamSamplesForClippedDuration(long clippedDurationUs)
```

Discards upstream samples that exceed the given clipped duration of the stream.

| Parameters |
|---|---|
| `long clippedDurationUs` | The clipped duration of the stream in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not known. |

### getAdjustedSeekPositionUs

```
public long getAdjustedSeekPositionUs(
    long positionUs,
    SeekParameters seekParameters
)
```

Adjusts a seek position given the specified `https://developer.android.com/reference/androidx/media3/exoplayer/SeekParameters`. Chunk boundaries are used as sync points.

| Parameters |
|---|---|
| `long positionUs` | The seek position in microseconds. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/SeekParameters seekParameters` | Parameters that control how the seek is performed. |

| Returns |
|---|---|
| `long` | The adjusted seek position, in microseconds. |

### getBufferedPositionUs

```
public long getBufferedPositionUs()
```

Returns an estimate of the position up to which data is buffered.

| Returns |
|---|---|
| `long` | An estimate of the absolute position in microseconds up to which data is buffered, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` if the track is fully buffered. |

### getChunkSource

```
public T getChunkSource()
```

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSource` used by this stream.

### getFlags

```
@SampleStream.Flags
public int getFlags()
```

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.Flags` set on this stream.

The value returned by this method is allowed to change during playback. Callers should check the flags when needed.

### getNextLoadPositionUs

```
public long getNextLoadPositionUs()
```

Returns the next load time, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` if loading has finished.

### isLoading

```
public boolean isLoading()
```

Returns whether the loader is currently loading.

### isReady

```
public boolean isReady()
```

Returns whether data is available to be read.

Note: If the stream has ended then a buffer with the end of stream flag can always be read from `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)`. Hence an ended stream is always ready.

| Returns |
|---|---|
| `boolean` | Whether data is available to be read. |

### mayHaveInitialDiscontinuity

```
public boolean mayHaveInitialDiscontinuity()
```

Returns whether there could be a pending initial discontinuity that needs to be consumed by `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()`.

### maybeThrowError

```
public void maybeThrowError()
```

Throws an error that's preventing data from being read. Does nothing if no such error exists.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | The underlying error. |

### onLoadCanceled

```
public void onLoadCanceled(
    Chunk loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    boolean released
)
```

Called when a load has been canceled.

Note: If the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` has not been released then there is guaranteed to be a memory barrier between `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` exiting and this callback being called. If the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` has been released then this callback may be called before `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` exits.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable` | The loadable whose load has been canceled. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load was canceled. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called up to the point at which it was canceled. |
| `boolean released` | True if the load was canceled because the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` was released. False otherwise. |

### onLoadCompleted

```
public void onLoadCompleted(
    Chunk loadable,
    long elapsedRealtimeMs,
    long loadDurationMs
)
```

Called when a load has completed.

Note: There is guaranteed to be a memory barrier between `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` exiting and this callback being called.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable` | The loadable whose load has completed. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load ended. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called. |

### onLoadError

```
public Loader.LoadErrorAction onLoadError(
    Chunk loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount
)
```

Called when a load encounters an error.

Note: There is guaranteed to be a memory barrier between `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` exiting and this callback being called.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable` | The loadable whose load has encountered an error. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the error occurred. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called up to the point at which the error occurred. |
| `https://developer.android.com/reference/java/io/IOException.html error` | The load error. |
| `int errorCount` | The number of errors this load has encountered, including this one. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.LoadErrorAction` | The desired error handling action. One of `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#RETRY()`, `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#RETRY_RESET_ERROR_COUNT()`, `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#DONT_RETRY()`, `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#DONT_RETRY_FATAL()` or a retry action created by `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#createRetryAction(boolean,long)`. |

### onLoadStarted

```
public void onLoadStarted(
    Chunk loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    int retryCount
)
```

Called when a load has started for the first time or through a retry.

This is called for the first time with `retryCount == 0` just **before** the load is started.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadable` | The loadable whose load has started. |
| `long elapsedRealtimeMs` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load attempts to start. |
| `long loadDurationMs` | The duration in milliseconds of the load since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called. |
| `int retryCount` | The number of failed attempts since `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called (this is zero for the first load attempt). |

### onLoaderReleased

```
public void onLoaderReleased()
```

Called when the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader` has finished being released.

### readData

```
public int readData(
    FormatHolder formatHolder,
    DecoderInputBuffer buffer,
    @SampleStream.ReadFlags int readFlags
)
```

Attempts to read from the stream.

If the stream has ended then `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag is set on `
buffer` and `https://developer.android.com/reference/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned. Else if no data is available then `https://developer.android.com/reference/androidx/media3/common/C#RESULT_NOTHING_READ()` is returned. Else if the format of the media is changing or if `
formatRequired` is set then `formatHolder` is populated and `https://developer.android.com/reference/androidx/media3/common/C#RESULT_FORMAT_READ()` is returned. Else `buffer` is populated and `https://developer.android.com/reference/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/FormatHolder formatHolder` | A `https://developer.android.com/reference/androidx/media3/exoplayer/FormatHolder` to populate in the case of reading a format. |
| `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer buffer` | A `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` to populate in the case of reading a sample or the end of the stream. If the end of the stream has been reached, the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag will be set on the buffer. |
| `@https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.ReadFlags int readFlags` | Flags controlling the behavior of this read operation. |

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream.ReadDataResult` of the read operation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer.InsufficientCapacityException` | If the `buffer` has insufficient capacity to hold the data of a sample being read. The buffer `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#timeUs()` and flags are populated if this exception is thrown, but the read position is not advanced. |

### reevaluateBuffer

```
public void reevaluateBuffer(long positionUs)
```

Re-evaluates the buffer given the playback position.

Re-evaluation may discard buffered media or cancel ongoing loads so that media can be re-buffered in a different quality.

| Parameters |
|---|---|
| `long positionUs` | The current playback position in microseconds. If playback of this period has not yet started, the value will be the starting position in this period minus the duration of any media in previous periods still to be played. |

### release

```
public void release()
```

Releases the stream.

This method should be called when the stream is no longer required. Either this method or `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#release(androidx.media3.exoplayer.source.chunk.ChunkSampleStream.ReleaseCallback<T>)` can be used to release this stream.

### release

```
public void release(@Nullable ChunkSampleStream.ReleaseCallback<T> callback)
```

Releases the stream.

This method should be called when the stream is no longer required. Either this method or `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#release()` can be used to release this stream.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.ReleaseCallback<T> callback` | An optional callback to be called on the loading thread once the loader has been released. |

### seekToUs

```
public void seekToUs(long positionUs)
```

Seeks to the specified position in microseconds.

| Parameters |
|---|---|
| `long positionUs` | The seek position in microseconds. |

### selectEmbeddedTrack

```
public ChunkSampleStream.EmbeddedSampleStream selectEmbeddedTrack(long positionUs, int trackType)
```

Selects the embedded track, returning a new `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` from which the track's samples can be consumed. `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream#release()` must be called on the returned stream when the track is no longer required, and before calling this method again to obtain another stream for the same track.

| Parameters |
|---|---|
| `long positionUs` | The current playback position in microseconds. |
| `int trackType` | The type of the embedded track to enable. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` for the embedded track. |

### setEndPositionUs

```
public void setEndPositionUs(long endPositionUs)
```

Sets the end position at which the period stops loading and providing samples.

If a value other than `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` is set, the implementation will stop returning samples from the created `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleStream` instances beyond the specified end position and mark further reads with `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()`. The stream may return additional out of order samples required for decoding.

| Parameters |
|---|---|
| `long endPositionUs` | The requested end position, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()` to not set an end position. |

### setSuppressRead

```
public void setSuppressRead(boolean suppressRead)
```

Sets whether to suppress any read operation from the stream.

| Parameters |
|---|---|
| `boolean suppressRead` | Whether to suppress reads. |

### setUsesStreamPrerollFlags

```
public void setUsesStreamPrerollFlags()
```

Sets whether `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#mayHaveInitialDiscontinuity()` should block on a pending initial discontinuity that has not yet been consumed by `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()`.

### skipData

```
public int skipData(long positionUs)
```

Attempts to skip to the keyframe before the specified position, or to the end of the stream if `positionUs` is beyond it.

| Parameters |
|---|---|
| `long positionUs` | The specified time. |

| Returns |
|---|---|
| `int` | The number of samples that were skipped. |