# InitializationChunk

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/InitializationChunk.java+class:androidx.media3.exoplayer.source.chunk.InitializationChunk)

*** ** * ** ***


```
@UnstableApi
public final class InitializationChunk extends Chunk
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.exoplayer.source.chunk.Chunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk) ||
|   | ↳ | [androidx.media3.exoplayer.source.chunk.InitializationChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk) |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk` that uses an `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to decode initialization data for single track.

## Summary

| ### Public fields |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#chunkIndex()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#InitializationChunk(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,androidx.media3.common.Format,int,java.lang.Object,androidx.media3.exoplayer.source.chunk.ChunkExtractor)( https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, https://developer.android.com/reference/androidx/media3/common/Format trackFormat, @https://developer.android.com/reference/androidx/media3/common/C.SelectionReason int trackSelectionReason, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html trackSelectionData, https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor chunkExtractor )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#cancelLoad()()` Cancels the load. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#getChunkIndex()()` Returns the `https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` obtained from the initialization chunk, or null if a `https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` has not been obtained. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#init(androidx.media3.exoplayer.source.chunk.ChunkExtractor.TrackOutputProvider)(https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider trackOutputProvider)` Initializes the chunk for loading, setting a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider` for track outputs to which formats will be written as they are loaded. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk#load()()` Performs the load, returning on completion or cancellation. |

| ### Inherited fields |
|---|
| From [androidx.media3.exoplayer.source.chunk.Chunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk) |---|---| | `final https://developer.android.com/reference/androidx/media3/datasource/StatsDataSource` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#dataSource()` | | `final https://developer.android.com/reference/androidx/media3/datasource/DataSpec` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#dataSpec()` The `https://developer.android.com/reference/androidx/media3/datasource/DataSpec` that defines the data to be loaded. | | `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#endTimeUs()` The end time of the media contained by the chunk, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the data being loaded does not contain media samples. | | `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#loadTaskId()` Identifies the load task for this loadable. | | `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#startTimeUs()` The start time of the media contained by the chunk, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the data being loaded does not contain media samples. | | `final @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#steeredPathwayId()` The ID of the steered pathway from which data is being loaded, or `null` if not applicable. | | `final https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackFormat()` The format of the track to which this chunk belongs. | | `final @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackSelectionData()` Optional data associated with the selection of the track to which this chunk belongs. | | `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.SelectionReason https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackSelectionReason()` One of the `https://developer.android.com/reference/androidx/media3/common/C.SelectionReason` if the chunk belongs to a track. | | `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.DataType https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#type()` The `https://developer.android.com/reference/androidx/media3/common/C.DataType` of the chunk. | |

| ### Inherited methods |
|---|
| From [androidx.media3.exoplayer.source.chunk.Chunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk) |---|---| | `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#bytesLoaded()()` Returns the number of bytes that have been loaded. | | `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#getDurationUs()()` Returns the duration of the chunk in microseconds. | | `final https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>>` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#getResponseHeaders()()` Returns the response headers associated with the last `https://developer.android.com/reference/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` call. | | `final https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#getUri()()` Returns the `https://developer.android.com/reference/android/net/Uri.html` associated with the last `https://developer.android.com/reference/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` call. | |

## Public fields

### chunkIndex

```
public @Nullable ChunkIndex chunkIndex
```

## Public constructors

### InitializationChunk

```
public InitializationChunk(
    DataSource dataSource,
    DataSpec dataSpec,
    Format trackFormat,
    @C.SelectionReason int trackSelectionReason,
    @Nullable Object trackSelectionData,
    ChunkExtractor chunkExtractor
)
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | The source from which the data should be loaded. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | Defines the data to be loaded. |
| `https://developer.android.com/reference/androidx/media3/common/Format trackFormat` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackFormat()`. |
| `@https://developer.android.com/reference/androidx/media3/common/C.SelectionReason int trackSelectionReason` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackSelectionReason()`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html trackSelectionData` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#trackSelectionData()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor chunkExtractor` | A wrapped extractor to use for parsing the initialization data. |

## Public methods

### cancelLoad

```
public void cancelLoad()
```

Cancels the load.

Loadable implementations should ensure that a currently executing `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` call will exit reasonably quickly after this method is called. The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` call may exit either by returning or by throwing an `https://developer.android.com/reference/java/io/IOException.html`.

If there is a currently executing `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` call, then the thread on which that call is being made will be interrupted immediately after the call to this method. Hence implementations do not need to (and should not attempt to) interrupt the loading thread themselves.

Although the loading thread will be interrupted, Loadable implementations should not use the interrupted status of the loading thread in `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()` to determine whether the load has been canceled. This approach is not robust \[Internal ref: b/79223737\]. Instead, implementations should use their own flag to signal cancelation (for example, using `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicBoolean.html`).

### getChunkIndex

```
public @Nullable ChunkIndex getChunkIndex()
```

Returns the `https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` obtained from the initialization chunk, or null if a `https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` has not been obtained.

### init

```
public void init(ChunkExtractor.TrackOutputProvider trackOutputProvider)
```

Initializes the chunk for loading, setting a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider` for track outputs to which formats will be written as they are loaded.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider trackOutputProvider` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor.TrackOutputProvider` for track outputs to which formats will be written as they are loaded. |

### load

```
public void load()
```

Performs the load, returning on completion or cancellation.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If the input could not be loaded. |