# 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
class ChunkSampleStream<T : ChunkSource?> : SampleStream, SequenceableLoader, Loader.Callback<Chunk!>, Loader.ReleaseCallback
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/C.TrackType primaryTrackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, embeddedTrackTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?, embeddedTrackFormats: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/media3/common/Format!>?, chunkSource: T!, callback: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SequenceableLoader.Callback<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream<T!>!>!, allocator: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator!, positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, drmSessionManager: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionManager!, drmEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmSessionEventListener.EventDispatcher!, loadErrorHandlingPolicy: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy!, mediaSourceEventDispatcher: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSourceEventListener.EventDispatcher!, handleInitialDiscontinuity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, firstChunkStartTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, downloadExecutor: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/ReleasableExecutor? )` Constructs an instance. |

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

| ### Public properties |
|---|---|
| `T!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#chunkSource()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#primaryTrackType()` |

### Inherited Constants

From [androidx.media3.exoplayer.source.SampleStream](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream) `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_HAS_PREROLL() = 4`

Specifies that the stream contains a preroll of decode-only samples.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_MAYBE_HAS_PREROLL() = 2`

Specifies that the stream may contain preroll samples.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_OMIT_SAMPLE_DATA() = 4`

Specifies that `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#data()`, `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#supplementalData()` and `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#cryptoInfo()` should not be populated when reading a sample buffer.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_PEEK() = 1`

Specifies that the read position should not be advanced if a sample buffer is read.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/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.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream#FLAG_STRICT_DURATION() = 1`

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

## Public constructors

### ChunkSampleStream

```
ChunkSampleStream(
    @C.TrackType primaryTrackType: Int,
    embeddedTrackTypes: IntArray<Int>?,
    embeddedTrackFormats: Array<Format!>?,
    chunkSource: T!,
    callback: SequenceableLoader.Callback<ChunkSampleStream<T!>!>!,
    allocator: Allocator!,
    positionUs: Long,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    loadErrorHandlingPolicy: LoadErrorHandlingPolicy!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher!,
    handleInitialDiscontinuity: Boolean,
    firstChunkStartTimeUs: Long,
    downloadExecutor: ReleasableExecutor?
)
```

Constructs an instance.

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

## Public functions

### consumeInitialDiscontinuity

```
fun consumeInitialDiscontinuity(): Boolean
```

Consumes a pending initial discontinuity.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the stream had an initial discontinuity. |

### continueLoading

```
fun continueLoading(loadingInfo: LoadingInfo!): Boolean
```

Attempts to continue loading.

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

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

### discardBuffer

```
fun discardBuffer(positionUs: Long, toKeyframe: Boolean): Unit
```

Discards buffered media up to the specified position.

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The position to discard up to, in microseconds. |
| `toKeyframe: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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

```
fun discardUpstreamSamplesForClippedDuration(clippedDurationUs: Long): Unit
```

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

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

### getAdjustedSeekPositionUs

```
fun getAdjustedSeekPositionUs(
    positionUs: Long,
    seekParameters: SeekParameters!
): Long
```

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

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The seek position in microseconds. |
| `seekParameters: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/SeekParameters!` | Parameters that control how the seek is performed. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The adjusted seek position, in microseconds. |

### getBufferedPositionUs

```
fun getBufferedPositionUs(): Long
```

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

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

### getFlags

```
@SampleStream.Flags
fun getFlags(): Int
```

Returns the `https://developer.android.com/reference/kotlin/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

```
fun getNextLoadPositionUs(): Long
```

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

### isLoading

```
fun isLoading(): Boolean
```

Returns whether the loader is currently loading.

### isReady

```
fun isReady(): Boolean
```

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/kotlin/androidx/media3/exoplayer/source/SampleStream#readData(androidx.media3.exoplayer.FormatHolder,androidx.media3.decoder.DecoderInputBuffer,int)`. Hence an ended stream is always ready.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether data is available to be read. |

### mayHaveInitialDiscontinuity

```
fun mayHaveInitialDiscontinuity(): Boolean
```

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

### maybeThrowError

```
fun maybeThrowError(): Unit
```

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

```
fun onLoadCanceled(
    loadable: Chunk!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    released: Boolean
): Unit
```

Called when a load has been canceled.

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

| Parameters |
|---|---|
| `loadable: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The loadable whose load has been canceled. |
| `elapsedRealtimeMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load was canceled. |
| `loadDurationMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The duration in milliseconds of the load since `https://developer.android.com/reference/kotlin/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. |
| `released: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | True if the load was canceled because the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader` was released. False otherwise. |

### onLoadCompleted

```
fun onLoadCompleted(
    loadable: Chunk!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long
): Unit
```

Called when a load has completed.

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

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

### onLoadError

```
fun onLoadError(
    loadable: Chunk!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    error: IOException!,
    errorCount: Int
): Loader.LoadErrorAction!
```

Called when a load encounters an error.

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

| Parameters |
|---|---|
| `loadable: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The loadable whose load has encountered an error. |
| `elapsedRealtimeMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the error occurred. |
| `loadDurationMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The duration in milliseconds of the load since `https://developer.android.com/reference/kotlin/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. |
| `error: https://developer.android.com/reference/java/io/IOException.html!` | The load error. |
| `errorCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of errors this load has encountered, including this one. |

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

### onLoadStarted

```
fun onLoadStarted(
    loadable: Chunk!,
    elapsedRealtimeMs: Long,
    loadDurationMs: Long,
    retryCount: Int
): Unit
```

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 |
|---|---|
| `loadable: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The loadable whose load has started. |
| `elapsedRealtimeMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` when the load attempts to start. |
| `loadDurationMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The duration in milliseconds of the load since `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader#startLoading(T,androidx.media3.exoplayer.upstream.Loader.Callback<T>,int)` was called. |
| `retryCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of failed attempts since `https://developer.android.com/reference/kotlin/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

```
fun onLoaderReleased(): Unit
```

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

### readData

```
fun readData(
    formatHolder: FormatHolder!,
    buffer: DecoderInputBuffer!,
    @SampleStream.ReadFlags readFlags: Int
): Int
```

Attempts to read from the stream.

If the stream has ended then `https://developer.android.com/reference/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag is set on `
buffer` and `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned. Else if no data is available then `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/C#RESULT_FORMAT_READ()` is returned. Else `buffer` is populated and `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_BUFFER_READ()` is returned.

| Parameters |
|---|---|
| `formatHolder: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/FormatHolder!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/FormatHolder` to populate in the case of reading a format. |
| `buffer: https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer!` | A `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM()` flag will be set on the buffer. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.ReadFlags readFlags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Flags controlling the behavior of this read operation. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/SampleStream.ReadDataResult` of the read operation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/decoder/DecoderInputBuffer#timeUs()` and flags are populated if this exception is thrown, but the read position is not advanced. |

### reevaluateBuffer

```
fun reevaluateBuffer(positionUs: Long): Unit
```

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 |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | 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

```
fun release(): Unit
```

Releases the stream.

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

### release

```
fun release(callback: ChunkSampleStream.ReleaseCallback<T!>?): Unit
```

Releases the stream.

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

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

### seekToUs

```
fun seekToUs(positionUs: Long): Unit
```

Seeks to the specified position in microseconds.

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The seek position in microseconds. |

### selectEmbeddedTrack

```
fun selectEmbeddedTrack(positionUs: Long, trackType: Int): ChunkSampleStream.EmbeddedSampleStream!
```

Selects the embedded track, returning a new `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream.EmbeddedSampleStream` from which the track's samples can be consumed. `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current playback position in microseconds. |
| `trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the embedded track to enable. |

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

### setEndPositionUs

```
fun setEndPositionUs(endPositionUs: Long): Unit
```

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

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

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

### setSuppressRead

```
fun setSuppressRead(suppressRead: Boolean): Unit
```

Sets whether to suppress any read operation from the stream.

| Parameters |
|---|---|
| `suppressRead: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to suppress reads. |

### setUsesStreamPrerollFlags

```
fun setUsesStreamPrerollFlags(): Unit
```

Sets whether `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream#consumeInitialDiscontinuity()`.

### skipData

```
fun skipData(positionUs: Long): Int
```

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

| Parameters |
|---|---|
| `positionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The specified time. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of samples that were skipped. |

## Public properties

### chunkSource

```
val chunkSource: T!
```

### primaryTrackType

```
@C.TrackType
val primaryTrackType: Int
```