# FakeChunkSource

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

*** ** * ** ***


```
@UnstableApi
class FakeChunkSource : ChunkSource
```

<br />

*** ** * ** ***

Fake `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSource` with adaptive media chunks of a given duration.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource.Factory` Factory for a `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#FakeChunkSource(androidx.media3.exoplayer.trackselection.ExoTrackSelection,androidx.media3.datasource.DataSource,androidx.media3.test.utils.FakeAdaptiveDataSet)( trackSelection: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ExoTrackSelection!, dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSet: https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeAdaptiveDataSet! )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#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/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#getNextChunk(androidx.media3.exoplayer.LoadingInfo,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.ChunkHolder)( loadingInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/LoadingInfo!, loadPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>!, out: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkHolder! )` Returns the next chunk to load. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#getPreferredQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)( playbackPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>! )` Evaluates whether `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`s should be removed from the back of the queue. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#maybeThrowError()()` If the source is currently having difficulty providing chunks, then this method throws the underlying error. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#onChunkLoadCompleted(androidx.media3.exoplayer.source.chunk.Chunk)(chunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!)` Called when the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` has finished loading a chunk obtained from this source. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#onChunkLoadError(androidx.media3.exoplayer.source.chunk.Chunk,boolean,androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo,androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)( chunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!, cancelable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, loadErrorInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy.LoadErrorInfo!, loadErrorHandlingPolicy: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy! )` Called when the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` encounters an error loading a chunk obtained from this source. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#release()()` Releases any held resources. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#shouldCancelLoad(long,androidx.media3.exoplayer.source.chunk.Chunk,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)( playbackPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, loadingChunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!, queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>! )` Returns whether an ongoing load of a chunk should be canceled. |

| ### Protected functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeChunkSource#createMediaChunk(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,androidx.media3.common.Format,int,java.lang.Object,long,long,long,int,androidx.media3.common.Format)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, trackFormat: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!, @https://developer.android.com/reference/kotlin/androidx/media3/common/C.SelectionReason trackSelectionReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, trackSelectionData: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, startTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, endTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, chunkIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, @https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, sampleFormat: https://developer.android.com/reference/kotlin/androidx/media3/common/Format! )` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk` for the given parameters. |

## Public constructors

### FakeChunkSource

```
FakeChunkSource(
    trackSelection: ExoTrackSelection!,
    dataSource: DataSource!,
    dataSet: FakeAdaptiveDataSet!
)
```

## Public functions

### 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. |

### getNextChunk

```
fun getNextChunk(
    loadingInfo: LoadingInfo!,
    loadPositionUs: Long,
    queue: (Mutable)List<MediaChunk!>!,
    out: ChunkHolder!
): Unit
```

Returns the next chunk to load.

If a chunk is available then `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkHolder#chunk()` is set. If the end of the stream has been reached then `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkHolder#endOfStream()` is set. If a chunk is not available but the end of the stream has not been reached, the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkHolder` is not modified.

| Parameters |
|---|---|
| `loadingInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/LoadingInfo!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/LoadingInfo` when loading request is made. |
| `loadPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current load position in microseconds. If `queue` is empty, this is the starting position from which chunks should be provided. Else it's equal to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk#endTimeUs()` of the last chunk in the `queue`. |
| `queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>!` | The queue of buffered `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`s. |
| `out: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkHolder!` | A holder to populate. |

### getPreferredQueueSize

```
fun getPreferredQueueSize(
    playbackPositionUs: Long,
    queue: (Mutable)List<MediaChunk!>!
): Int
```

Evaluates whether `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`s should be removed from the back of the queue.

Removing `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`s from the back of the queue can be useful if they could be replaced with chunks of a significantly higher quality (e.g. because the available bandwidth has substantially increased).

Will only be called if no `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk` in the queue is currently loading.

| Parameters |
|---|---|
| `playbackPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current playback position, in microseconds. |
| `queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>!` | The queue of buffered `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`s. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The preferred queue size. |

### maybeThrowError

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

If the source is currently having difficulty providing chunks, then this method throws the underlying error. Otherwise does nothing.

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

### onChunkLoadCompleted

```
fun onChunkLoadCompleted(chunk: Chunk!): Unit
```

Called when the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` has finished loading a chunk obtained from this source.

| Parameters |
|---|---|
| `chunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The chunk whose load has been completed. |

### onChunkLoadError

```
fun onChunkLoadError(
    chunk: Chunk!,
    cancelable: Boolean,
    loadErrorInfo: LoadErrorHandlingPolicy.LoadErrorInfo!,
    loadErrorHandlingPolicy: LoadErrorHandlingPolicy!
): Boolean
```

Called when the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` encounters an error loading a chunk obtained from this source.

| Parameters |
|---|---|
| `chunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The chunk whose load encountered the error. |
| `cancelable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the load can be canceled. |
| `loadErrorInfo: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy.LoadErrorInfo!` | The load error info. |
| `loadErrorHandlingPolicy: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy!` | The load error handling policy to customize the behaviour of handling the load error. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the load should be canceled so that a replacement chunk can be loaded instead. Must be `false` if `cancelable` is `false`. If `true`, `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkSource#getNextChunk(androidx.media3.exoplayer.LoadingInfo,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.ChunkHolder)` will be called to obtain the replacement chunk. |

### release

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

Releases any held resources.

### shouldCancelLoad

```
fun shouldCancelLoad(
    playbackPositionUs: Long,
    loadingChunk: Chunk!,
    queue: (Mutable)List<MediaChunk!>!
): Boolean
```

Returns whether an ongoing load of a chunk should be canceled.

| Parameters |
|---|---|
| `playbackPositionUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The current playback position, in microseconds. |
| `loadingChunk: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk!` | The currently loading `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk`. |
| `queue: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk!>!` | The queue of buffered `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the ongoing load of `loadingChunk` should be canceled. |

## Protected functions

### createMediaChunk

```
protected fun createMediaChunk(
    dataSource: DataSource!,
    dataSpec: DataSpec!,
    trackFormat: Format!,
    @C.SelectionReason trackSelectionReason: Int,
    trackSelectionData: Any?,
    startTimeUs: Long,
    endTimeUs: Long,
    chunkIndex: Long,
    @C.TrackType trackType: Int,
    sampleFormat: Format!
): MediaChunk!
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk` for the given parameters.

Subclasses can override this method to return custom `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/MediaChunk` implementations.