# 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
public final class DashUtil
```

<br />

*** ** * ** ***

Utility methods for DASH streams.

## Summary

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

## Public methods

### buildDataSpec

```
public static DataSpec buildDataSpec(
    Representation representation,
    BaseUrl baseUrl,
    RangedUri requestUri,
    int flags,
    Map<String, String> httpRequestHeaders
)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/Representation representation` | The `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/Representation` to which the request belongs. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/BaseUrl baseUrl` | The `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/BaseUrl` to which the request belongs. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri requestUri` | The `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` of the data to request. |
| `int flags` | Flags to be set on the returned `https://developer.android.com/reference/androidx/media3/datasource/DataSpec`. See `https://developer.android.com/reference/androidx/media3/datasource/DataSpec.Builder#setFlags(int)`. |
| `https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> httpRequestHeaders` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSpec#httpRequestHeaders()`. |

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

### buildDataSpec

```
public static DataSpec [buildDataSpec](https://developer.android.com/reference/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,
    String baseUrl,
    RangedUri requestUri,
    int flags,
    Map<String, String> httpRequestHeaders
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/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

```
public static @Nullable ChunkIndex loadChunkIndex(
    DataSource dataSource,
    int trackType,
    Representation representation
)
```

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

Uses the first base URL for loading the index.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` | The `https://developer.android.com/reference/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

```
public static @Nullable ChunkIndex loadChunkIndex(
    DataSource dataSource,
    int trackType,
    Representation representation,
    int baseUrlIndex
)
```

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` | The `https://developer.android.com/reference/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

```
public static @Nullable Format loadFormatWithDrmInitData(DataSource dataSource, Period period)
```

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Format` | The loaded `https://developer.android.com/reference/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

```
public static void loadInitializationData(
    ChunkExtractor chunkExtractor,
    DataSource dataSource,
    Representation representation,
    boolean loadIndex
)
```

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

Uses the first base URL for loading the initialization data.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor chunkExtractor` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/ChunkExtractor` to use. |
| `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/exoplayer/dash/manifest/Representation representation` | The representation which initialization chunk belongs to. |
| `boolean loadIndex` | 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

```
public static DashManifest loadManifest(DataSource dataSource, Uri uri)
```

Loads a DASH manifest.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/DashManifest` | An instance of `https://developer.android.com/reference/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

```
public static @Nullable Format loadSampleFormat(
    DataSource dataSource,
    int trackType,
    Representation representation
)
```

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

Uses the first base URL for loading the format.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Format` | the sample `https://developer.android.com/reference/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

```
public static @Nullable Format loadSampleFormat(
    DataSource dataSource,
    int trackType,
    Representation representation,
    int baseUrlIndex
)
```

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/Format` | the sample `https://developer.android.com/reference/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

```
public static String resolveCacheKey(Representation representation, RangedUri rangedUri)
```

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

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

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The cache key. |