# DefaultSsChunkSource

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

*** ** * ** ***


```
@UnstableApi
public class DefaultSsChunkSource implements SsChunkSource
```

<br />

*** ** * ** ***

A default `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/SsChunkSource` implementation.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource.Factory implements https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/SsChunkSource.Factory` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#DefaultSsChunkSource(androidx.media3.exoplayer.upstream.LoaderErrorThrower,androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest,int,androidx.media3.exoplayer.trackselection.ExoTrackSelection,androidx.media3.datasource.DataSource,androidx.media3.exoplayer.upstream.CmcdConfiguration,androidx.media3.extractor.text.SubtitleParser.Factory,boolean)( https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoaderErrorThrower manifestLoaderErrorThrower, https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/manifest/SsManifest manifest, int streamElementIndex, https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection, https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration cmcdConfiguration, https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory, boolean parseSubtitlesDuringExtraction )` |

| ### Public methods |
|---|---|
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#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`. |
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#getNextChunk(androidx.media3.exoplayer.LoadingInfo,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.ChunkHolder)( https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo loadingInfo, long loadPositionUs, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue, https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkHolder out )` Returns the next chunk to load. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#getPreferredQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)(long playbackPositionUs, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue)` Evaluates whether `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s should be removed from the back of the queue. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#maybeThrowError()()` If the source is currently having difficulty providing chunks, then this method throws the underlying error. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#onChunkLoadCompleted(androidx.media3.exoplayer.source.chunk.Chunk)(https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk chunk)` Called when the `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` has finished loading a chunk obtained from this source. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#onChunkLoadError(androidx.media3.exoplayer.source.chunk.Chunk,boolean,androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo,androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)( https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk chunk, boolean cancelable, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoadErrorHandlingPolicy loadErrorHandlingPolicy )` Called when the `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkSampleStream` encounters an error loading a chunk obtained from this source. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#release()()` Releases any held resources. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#shouldCancelLoad(long,androidx.media3.exoplayer.source.chunk.Chunk,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)( long playbackPositionUs, https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadingChunk, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue )` Returns whether an ongoing load of a chunk should be canceled. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#updateManifest(androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest)(https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/manifest/SsManifest newManifest)` Updates the manifest. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/DefaultSsChunkSource#updateTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection)(https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection)` Updates the track selection. |

## Public constructors

### DefaultSsChunkSource

```
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    ExoTrackSelection trackSelection,
    DataSource dataSource,
    @Nullable CmcdConfiguration cmcdConfiguration,
    SubtitleParser.Factory subtitleParserFactory,
    boolean parseSubtitlesDuringExtraction
)
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/LoaderErrorThrower manifestLoaderErrorThrower` | Throws errors affecting loading of manifests. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/manifest/SsManifest manifest` | The initial manifest. |
| `int streamElementIndex` | The index of the stream element in the manifest. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection` | The track selection. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | A `https://developer.android.com/reference/androidx/media3/datasource/DataSource` suitable for loading the media data. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration cmcdConfiguration` | The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/CmcdConfiguration` for this chunk source. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory subtitleParserFactory` | The `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleParser.Factory` for parsing subtitles during extraction. |
| `boolean parseSubtitlesDuringExtraction` | Whether to parse subtitles during extraction or rendering. |

## Public methods

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

### getNextChunk

```
public final void getNextChunk(
    LoadingInfo loadingInfo,
    long loadPositionUs,
    List<MediaChunk> queue,
    ChunkHolder out
)
```

Returns the next chunk to load.

If a chunk is available then `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkHolder#chunk()` is set. If the end of the stream has been reached then `https://developer.android.com/reference/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/androidx/media3/exoplayer/source/chunk/ChunkHolder` is not modified.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo loadingInfo` | The `https://developer.android.com/reference/androidx/media3/exoplayer/LoadingInfo` when loading request is made. |
| `long loadPositionUs` | 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/androidx/media3/exoplayer/source/chunk/Chunk#endTimeUs()` of the last chunk in the `queue`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkHolder out` | A holder to populate. |

### getPreferredQueueSize

```
public int getPreferredQueueSize(long playbackPositionUs, List<MediaChunk> queue)
```

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

Removing `https://developer.android.com/reference/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/androidx/media3/exoplayer/source/chunk/MediaChunk` in the queue is currently loading.

| Parameters |
|---|---|
| `long playbackPositionUs` | The current playback position, in microseconds. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s. |

| Returns |
|---|---|
| `int` | The preferred queue size. |

### maybeThrowError

```
public void maybeThrowError()
```

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

```
public void onChunkLoadCompleted(Chunk chunk)
```

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

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

### onChunkLoadError

```
public boolean onChunkLoadError(
    Chunk chunk,
    boolean cancelable,
    LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy
)
```

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

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

| Returns |
|---|---|
| `boolean` | 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/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

```
public void release()
```

Releases any held resources.

### shouldCancelLoad

```
public boolean shouldCancelLoad(
    long playbackPositionUs,
    Chunk loadingChunk,
    List<MediaChunk> queue
)
```

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

| Parameters |
|---|---|
| `long playbackPositionUs` | The current playback position, in microseconds. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadingChunk` | The currently loading `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`. |

| Returns |
|---|---|
| `boolean` | Whether the ongoing load of `loadingChunk` should be canceled. |

### updateManifest

```
public void updateManifest(SsManifest newManifest)
```

Updates the manifest.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/smoothstreaming/manifest/SsManifest newManifest` | The new manifest. |

### updateTrackSelection

```
public void updateTrackSelection(ExoTrackSelection trackSelection)
```

Updates the track selection.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection` | The new track selection instance. Must be equivalent to the previous one. |