@UnstableApi
public final class DashUtil


Utility methods for DASH streams.

Summary

Public methods

static DataSpec
buildDataSpec(
    Representation representation,
    RangedUri requestUri,
    int flags
)

This method is deprecated.

Use buildDataSpec instead.

static DataSpec
buildDataSpec(
    Representation representation,
    String baseUrl,
    RangedUri requestUri,
    int flags
)

This method is deprecated.

Use buildDataSpec instead.

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

Builds a DataSpec for a given RangedUri belonging to Representation.

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

Loads initialization and index data for the representation and returns the .

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

Loads initialization and index data for the representation and returns the .

static @Nullable Format

Loads a Format for acquiring keys for a given period in a DASH manifest.

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

Loads initialization data for the representation and optionally index data then returns a BundledChunkExtractor which contains the output.

static DashManifest
loadManifest(DataSource dataSource, Uri uri)

Loads a DASH manifest.

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

Loads initialization data for the representation and returns the sample Format.

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

Loads initialization data for the representation and returns the sample Format.

static String
resolveCacheKey(Representation representation, RangedUri rangedUri)

Resolves the cache key to be used when requesting the given ranged URI for the given .

Public methods

buildDataSpec

public static DataSpec buildDataSpec(
    Representation representation,
    RangedUri requestUri,
    int flags
)

buildDataSpec

public static DataSpec buildDataSpec(
    Representation representation,
    String baseUrl,
    RangedUri requestUri,
    int flags
)

buildDataSpec

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

Builds a DataSpec for a given RangedUri belonging to Representation.

Parameters
Representation representation

The Representation to which the request belongs.

String baseUrl

The base url with which to resolve the request URI.

RangedUri requestUri

The RangedUri of the data to request.

int flags

Flags to be set on the returned DataSpec. See setFlags.

Map<StringString> httpRequestHeaders

The httpRequestHeaders.

Returns
DataSpec

The DataSpec.

loadChunkIndex

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

Loads initialization and index data for the representation and returns the .

Uses the first base URL for loading the index.

Parameters
DataSource dataSource

The source from which the data should be loaded.

int trackType

The type of the representation. Typically one of the androidx.media3.common.CTRACK_TYPE_* constants.

Representation representation

The representation which initialization chunk belongs to.

Returns
@Nullable ChunkIndex

The ChunkIndex of the given representation, or null if no initialization or index data exists.

Throws
java.io.IOException

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 .

Parameters
DataSource dataSource

The source from which the data should be loaded.

int trackType

The type of the representation. Typically one of the androidx.media3.common.CTRACK_TYPE_* constants.

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
@Nullable ChunkIndex

The ChunkIndex of the given representation, or null if no initialization or index data exists.

Throws
java.io.IOException

Thrown when there is an error while loading.

loadFormatWithDrmInitData

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

Loads a Format for acquiring keys for a given period in a DASH manifest.

Parameters
DataSource dataSource

The DataSource from which data should be loaded.

Period period

The Period.

Returns
@Nullable Format

The loaded Format, or null if none is defined.

Throws
java.io.IOException

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 BundledChunkExtractor which contains the output.

Uses the first base URL for loading the initialization data.

Parameters
ChunkExtractor chunkExtractor

The ChunkExtractor to use.

DataSource dataSource

The source from which the data should be loaded.

Representation representation

The representation which initialization chunk belongs to.

boolean loadIndex

Whether to load index data too.

Throws
java.io.IOException

Thrown when there is an error while loading.

loadManifest

public static DashManifest loadManifest(DataSource dataSource, Uri uri)

Loads a DASH manifest.

Parameters
DataSource dataSource

The DataSource from which the manifest should be read.

Uri uri

The Uri of the manifest to be read.

Returns
DashManifest

An instance of DashManifest.

Throws
java.io.IOException

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

Uses the first base URL for loading the format.

Parameters
DataSource dataSource

The source from which the data should be loaded.

int trackType

The type of the representation. Typically one of the androidx.media3.common.CTRACK_TYPE_* constants.

Representation representation

The representation which initialization chunk belongs to.

Returns
@Nullable Format

the sample Format of the given representation.

Throws
java.io.IOException

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

Parameters
DataSource dataSource

The source from which the data should be loaded.

int trackType

The type of the representation. Typically one of the androidx.media3.common.CTRACK_TYPE_* constants.

Representation representation

The representation which initialization chunk belongs to.

int baseUrlIndex

The index of the base URL to be picked from the list of base URLs.

Returns
@Nullable Format

the sample Format of the given representation.

Throws
java.io.IOException

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 .

Parameters
Representation representation

The Representation to which the URI belongs to.

RangedUri rangedUri

The URI for which to resolve the cache key.

Returns
String

The cache key.