# Chunk

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

*** ** * ** ***


```
@UnstableApi
public abstract class Chunk implements Loader.Loadable
```

<br />

Known direct subclasses [DataChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/DataChunk), [InitializationChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/InitializationChunk), [MediaChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/DataChunk` | A base class for `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk` implementations where the data should be loaded into a ` byte[]` before being consumed. |
| `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. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` | An abstract base class for `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk`s that contain media samples. |

Known indirect subclasses [BaseMediaChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunk), [ContainerMediaChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk), [FakeMediaChunk](https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaChunk), [SingleSampleMediaChunk](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/SingleSampleMediaChunk)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunk` | A base implementation of `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` that outputs to a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkOutput`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ContainerMediaChunk` | A `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunk` that uses an `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to decode sample data. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaChunk` | Fake `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/SingleSampleMediaChunk` | **This class is deprecated.** The only use for this class is subtitle playback, but it is only compatible with legacy subtitle decoding, which is not supported by default. <br /> |

*** ** * ** ***

An abstract base class for `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable` implementations that load chunks of data required for the playback of streams.

## Summary

| ### Public fields |
|---|---|
| `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. |

| ### Protected fields |
|---|---|
| `final https://developer.android.com/reference/androidx/media3/datasource/StatsDataSource` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#dataSource()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#Chunk(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,int,androidx.media3.common.Format,int,java.lang.Object,long,long,java.lang.String)( 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/C.DataType int type, 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, long startTimeUs, long endTimeUs, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html steeredPathwayId )` |

| ### Public methods |
|---|---|
| `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. |

| ### Inherited methods |
|---|
| From [androidx.media3.exoplayer.upstream.Loader.Loadable](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable) |---|---| | `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#cancelLoad()()` Cancels the load. | | `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/Loader.Loadable#load()()` Performs the load, returning on completion or cancellation. | |

## Public fields

### dataSpec

```
public final DataSpec dataSpec
```

The `https://developer.android.com/reference/androidx/media3/datasource/DataSpec` that defines the data to be loaded.

### endTimeUs

```
public final long 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.

### loadTaskId

```
public final long loadTaskId
```

Identifies the load task for this loadable.

### startTimeUs

```
public final long 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.

### steeredPathwayId

```
public final @Nullable String steeredPathwayId
```

The ID of the steered pathway from which data is being loaded, or `null` if not applicable.

### trackFormat

```
public final Format trackFormat
```

The format of the track to which this chunk belongs.

### trackSelectionData

```
public final @Nullable Object trackSelectionData
```

Optional data associated with the selection of the track to which this chunk belongs. Null if the chunk does not belong to a track, or if there is no associated track selection data.

### trackSelectionReason

```
@C.SelectionReason
public final int trackSelectionReason
```

One of the `https://developer.android.com/reference/androidx/media3/common/C.SelectionReason` if the chunk belongs to a track. `https://developer.android.com/reference/androidx/media3/common/C#SELECTION_REASON_UNKNOWN()` if the chunk does not belong to a track, or if the selection reason is unknown.

### type

```
@C.DataType
public final int type
```

The `https://developer.android.com/reference/androidx/media3/common/C.DataType` of the chunk. For reporting only.

## Protected fields

### dataSource

```
protected final StatsDataSource dataSource
```

## Public constructors

### Chunk

```
public Chunk(
    DataSource dataSource,
    DataSpec dataSpec,
    @C.DataType int type,
    Format trackFormat,
    @C.SelectionReason int trackSelectionReason,
    @Nullable Object trackSelectionData,
    long startTimeUs,
    long endTimeUs,
    @Nullable String steeredPathwayId
)
```

| 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/C.DataType int type` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#type()`. |
| `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()`. |
| `long startTimeUs` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#startTimeUs()`. |
| `long endTimeUs` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#endTimeUs()`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html steeredPathwayId` | See `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk#steeredPathwayId()`. |

## Public methods

### bytesLoaded

```
public final long bytesLoaded()
```

Returns the number of bytes that have been loaded. Must only be called after the load completed, failed, or was canceled.

### getDurationUs

```
public final long getDurationUs()
```

Returns the duration of the chunk in microseconds.

### getResponseHeaders

```
public final Map<String, List<String>> getResponseHeaders()
```

Returns the response headers associated with the last `https://developer.android.com/reference/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` call. Must only be called after the load completed, failed, or was canceled.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource#getResponseHeaders()` |   |

### getUri

```
public final Uri 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. If redirection occurred, this is the redirected uri. Must only be called after the load completed, failed, or was canceled.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource#getUri()` |   |