Package com.google.android.exoplayer2.source.chunk

## Class Chunk

- java.lang.Object
- - com.google.android.exoplayer2.source.chunk.Chunk

- All Implemented Interfaces:
    `Loader.Loadable`
  Direct Known Subclasses:
    `DataChunk`, `InitializationChunk`, `MediaChunk`

      public abstract class Chunk
      extends Object
      implements Loader.Loadable

  An abstract base class for `Loader.Loadable` implementations that load chunks of data required for the playback of streams.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected StatsDataSource` | `dataSource` |
    `DataSpec` | `dataSpec` | The `DataSpec` that defines the data to be loaded.
    `long` | `endTimeUs` | The end time of the media contained by the chunk, or `C.TIME_UNSET` if the data being loaded does not contain media samples.
    `long` | `loadTaskId` | Identifies the load task for this loadable.
    `long` | `startTimeUs` | The start time of the media contained by the chunk, or `C.TIME_UNSET` if the data being loaded does not contain media samples.
    `Format` | `trackFormat` | The format of the track to which this chunk belongs.
    `Object` | `trackSelectionData` | Optional data associated with the selection of the track to which this chunk belongs.
    `@com.google.android.exoplayer2.C.SelectionReason int` | `trackSelectionReason` | One of the `selection reasons` if the chunk belongs to a track.
    `@com.google.android.exoplayer2.C.DataType int` | `type` | The `data type` of the chunk.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Chunk​(DataSource dataSource, DataSpec dataSpec, @com.google.android.exoplayer2.C.DataType int type, Format trackFormat, @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `long` | `bytesLoaded()` | Returns the number of bytes that have been loaded.
    `long` | `getDurationUs()` | Returns the duration of the chunk in microseconds.
    `Map<String,​List<String>>` | `getResponseHeaders()` | Returns the response headers associated with the last `DataSource.open(com.google.android.exoplayer2.upstream.DataSpec)` call.
    `Uri` | `getUri()` | Returns the `Uri` associated with the last `DataSource.open(com.google.android.exoplayer2.upstream.DataSpec)` call.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.upstream.Loader.Loadable

      `cancelLoad, load`

- - ### Field Detail

    - #### loadTaskId

          public final long loadTaskId

      Identifies the load task for this loadable.

    - #### dataSpec

          public final DataSpec dataSpec

      The `DataSpec` that defines the data to be loaded.

    - #### type

          public final @com.google.android.exoplayer2.C.DataType int type

      The `data type` of the chunk. For reporting only.

    - #### trackFormat

          public final Format trackFormat

      The format of the track to which this chunk belongs.

    - #### trackSelectionReason

          public final @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason

      One of the `selection reasons` if the chunk belongs to a track. `C.SELECTION_REASON_UNKNOWN` if the chunk does not belong to a track, or if the selection reason is unknown.

    - #### trackSelectionData

          @Nullable
          public final 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.

    - #### startTimeUs

          public final long startTimeUs

      The start time of the media contained by the chunk, or `C.TIME_UNSET` if the data being loaded does not contain media samples.

    - #### endTimeUs

          public final long endTimeUs

      The end time of the media contained by the chunk, or `C.TIME_UNSET` if the data being loaded does not contain media samples.

    - #### dataSource

          protected final StatsDataSource dataSource

  - ### Constructor Detail

    - #### Chunk

          public Chunk​(DataSource dataSource,
                       DataSpec dataSpec,
                       @com.google.android.exoplayer2.C.DataType int type,
                       Format trackFormat,
                       @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason,
                       @Nullable
                       Object trackSelectionData,
                       long startTimeUs,
                       long endTimeUs)

      Parameters:
        `dataSource` - The source from which the data should be loaded.
        `dataSpec` - Defines the data to be loaded.
        `type` - See `type`.
        `trackFormat` - See `trackFormat`.
        `trackSelectionReason` - See `trackSelectionReason`.
        `trackSelectionData` - See `trackSelectionData`.
        `startTimeUs` - See `startTimeUs`.
        `endTimeUs` - See `endTimeUs`.

  - ### Method Detail

    - #### getDurationUs

          public final long getDurationUs()

      Returns the duration of the chunk in microseconds.

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

    - #### getUri

          public final Uri getUri()

      Returns the `Uri` associated with the last `DataSource.open(com.google.android.exoplayer2.upstream.DataSpec)` call. If redirection occurred, this is the redirected uri. Must only be called after the load completed, failed, or was canceled.
      See Also:
        `DataSource.getUri()`

    - #### getResponseHeaders

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

      Returns the response headers associated with the last `DataSource.open(com.google.android.exoplayer2.upstream.DataSpec)` call. Must only be called after the load completed, failed, or was canceled.
      See Also:
        `DataSource.getResponseHeaders()`