# DashUtil

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

*** ** * ** ***


```
@UnstableApi
class DashUtil
```

<br />

*** ** * ** ***

Utility methods for DASH streams.

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#buildDataSpec(androidx.media3.exoplayer.dash.manifest.Representation,androidx.media3.exoplayer.dash.manifest.BaseUrl,androidx.media3.exoplayer.dash.manifest.RangedUri,int,java.util.Map<java.lang.String,java.lang.String>)( representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, baseUrl: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/BaseUrl!, requestUri: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri!, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, httpRequestHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>! )` Builds a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` for a given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri` belonging to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation` and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/BaseUrl`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | `[buildDataSpec](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#buildDataSpec(androidx.media3.exoplayer.dash.manifest.Representation,java.lang.String,androidx.media3.exoplayer.dash.manifest.RangedUri,int,java.util.Map<java.lang.String,java.lang.String>))( representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, baseUrl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, requestUri: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri!, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, httpRequestHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>! )` **This function is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#buildDataSpec(androidx.media3.exoplayer.dash.manifest.Representation,androidx.media3.exoplayer.dash.manifest.BaseUrl,androidx.media3.exoplayer.dash.manifest.RangedUri,int,java.util.Map<java.lang.String,java.lang.String>)` instead. <br /> |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadChunkIndex(androidx.media3.datasource.DataSource,int,androidx.media3.exoplayer.dash.manifest.Representation)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation! )` Loads initialization and index data for the `representation` and returns the `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadChunkIndex(androidx.media3.datasource.DataSource,int,androidx.media3.exoplayer.dash.manifest.Representation,int)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, baseUrlIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Loads initialization and index data for the `representation` and returns the `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadFormatWithDrmInitData(androidx.media3.datasource.DataSource,androidx.media3.exoplayer.dash.manifest.Period)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, period: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Period!)` Loads a `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` for acquiring keys for a given period in a DASH manifest. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadInitializationData(androidx.media3.exoplayer.source.chunk.ChunkExtractor,androidx.media3.datasource.DataSource,androidx.media3.exoplayer.dash.manifest.Representation,boolean)( chunkExtractor: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor!, dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, loadIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Loads initialization data for the `representation` and optionally index data then returns a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/BundledChunkExtractor` which contains the output. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/DashManifest!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadManifest(androidx.media3.datasource.DataSource,android.net.Uri)(dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, uri: https://developer.android.com/reference/android/net/Uri.html!)` Loads a DASH manifest. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadSampleFormat(androidx.media3.datasource.DataSource,int,androidx.media3.exoplayer.dash.manifest.Representation)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation! )` Loads initialization data for the `representation` and returns the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#loadSampleFormat(androidx.media3.datasource.DataSource,int,androidx.media3.exoplayer.dash.manifest.Representation,int)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, baseUrlIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Loads initialization data for the `representation` and returns the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#resolveCacheKey(androidx.media3.exoplayer.dash.manifest.Representation,androidx.media3.exoplayer.dash.manifest.RangedUri)(representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!, rangedUri: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri!)` Resolves the cache key to be used when requesting the given ranged URI for the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation`. |

## Public functions

### buildDataSpec

```
java-static fun buildDataSpec(
    representation: Representation!,
    baseUrl: BaseUrl!,
    requestUri: RangedUri!,
    flags: Int,
    httpRequestHeaders: (Mutable)Map<String!, String!>!
): DataSpec!
```

Builds a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` for a given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri` belonging to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation` and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/BaseUrl`.

| Parameters |
|---|---|
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation` to which the request belongs. |
| `baseUrl: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/BaseUrl!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/BaseUrl` to which the request belongs. |
| `requestUri: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri` of the data to request. |
| `flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Flags to be set on the returned `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec`. See `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec.Builder#setFlags(int)`. |
| `httpRequestHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec#httpRequestHeaders()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec`. |

### buildDataSpec

```
java-static fun [buildDataSpec](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#buildDataSpec(androidx.media3.exoplayer.dash.manifest.Representation,java.lang.String,androidx.media3.exoplayer.dash.manifest.RangedUri,int,java.util.Map<java.lang.String,java.lang.String>))(
    representation: Representation!,
    baseUrl: String!,
    requestUri: RangedUri!,
    flags: Int,
    httpRequestHeaders: (Mutable)Map<String!, String!>!
): DataSpec!
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashUtil#buildDataSpec(androidx.media3.exoplayer.dash.manifest.Representation,androidx.media3.exoplayer.dash.manifest.BaseUrl,androidx.media3.exoplayer.dash.manifest.RangedUri,int,java.util.Map<java.lang.String,java.lang.String>)` instead.

### loadChunkIndex

```
java-static fun loadChunkIndex(
    dataSource: DataSource!,
    trackType: Int,
    representation: Representation!
): ChunkIndex?
```

Loads initialization and index data for the `representation` and returns the `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex`.

Uses the first base URL for loading the index.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which the data should be loaded. |
| `trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the representation. Typically one of the `https://developer.android.com/reference/kotlin/androidx/media3/common/C``TRACK_TYPE_*` constants. |
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The representation which initialization chunk belongs to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex?` | The `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex` of the given representation, or null if no initialization or index data exists. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadChunkIndex

```
java-static fun loadChunkIndex(
    dataSource: DataSource!,
    trackType: Int,
    representation: Representation!,
    baseUrlIndex: Int
): ChunkIndex?
```

Loads initialization and index data for the `representation` and returns the `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex`.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which the data should be loaded. |
| `trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the representation. Typically one of the `https://developer.android.com/reference/kotlin/androidx/media3/common/C``TRACK_TYPE_*` constants. |
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The representation which initialization chunk belongs to. |
| `baseUrlIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the base URL with which to resolve the request URI. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex?` | The `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex` of the given representation, or null if no initialization or index data exists. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadFormatWithDrmInitData

```
java-static fun loadFormatWithDrmInitData(dataSource: DataSource!, period: Period!): Format?
```

Loads a `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` for acquiring keys for a given period in a DASH manifest.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` from which data should be loaded. |
| `period: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Period!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Period`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | The loaded `https://developer.android.com/reference/kotlin/androidx/media3/common/Format`, or null if none is defined. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadInitializationData

```
java-static fun loadInitializationData(
    chunkExtractor: ChunkExtractor!,
    dataSource: DataSource!,
    representation: Representation!,
    loadIndex: Boolean
): Unit
```

Loads initialization data for the `representation` and optionally index data then returns a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/BundledChunkExtractor` which contains the output.

Uses the first base URL for loading the initialization data.

| Parameters |
|---|---|
| `chunkExtractor: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/ChunkExtractor` to use. |
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which the data should be loaded. |
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The representation which initialization chunk belongs to. |
| `loadIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to load index data too. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadManifest

```
java-static fun loadManifest(dataSource: DataSource!, uri: Uri!): DashManifest!
```

Loads a DASH manifest.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` from which the manifest should be read. |
| `uri: https://developer.android.com/reference/android/net/Uri.html!` | The `https://developer.android.com/reference/android/net/Uri.html` of the manifest to be read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/DashManifest!` | An instance of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/DashManifest`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadSampleFormat

```
java-static fun loadSampleFormat(
    dataSource: DataSource!,
    trackType: Int,
    representation: Representation!
): Format?
```

Loads initialization data for the `representation` and returns the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format`.

Uses the first base URL for loading the format.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which the data should be loaded. |
| `trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the representation. Typically one of the `https://developer.android.com/reference/kotlin/androidx/media3/common/C``TRACK_TYPE_*` constants. |
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The representation which initialization chunk belongs to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` of the given representation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### loadSampleFormat

```
java-static fun loadSampleFormat(
    dataSource: DataSource!,
    trackType: Int,
    representation: Representation!,
    baseUrlIndex: Int
): Format?
```

Loads initialization data for the `representation` and returns the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format`.

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source from which the data should be loaded. |
| `trackType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The type of the representation. Typically one of the `https://developer.android.com/reference/kotlin/androidx/media3/common/C``TRACK_TYPE_*` constants. |
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The representation which initialization chunk belongs to. |
| `baseUrlIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the base URL to be picked from the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation#baseUrls()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Format?` | the sample `https://developer.android.com/reference/kotlin/androidx/media3/common/Format` of the given representation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | Thrown when there is an error while loading. |

### resolveCacheKey

```
java-static fun resolveCacheKey(representation: Representation!, rangedUri: RangedUri!): String!
```

Resolves the cache key to be used when requesting the given ranged URI for the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation`.

| Parameters |
|---|---|
| `representation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/Representation` to which the URI belongs to. |
| `rangedUri: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri!` | The URI for which to resolve the cache key. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The cache key. |