Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

UriMediaItem.Builder

public static final class UriMediaItem.Builder
extends MediaItem.Builder

java.lang.Object
   ↳ androidx.media2.common.MediaItem.Builder
     ↳ androidx.media2.common.UriMediaItem.Builder


This Builder class simplifies the creation of a UriMediaItem object.

Summary

Public constructors

UriMediaItem.Builder(Uri uri)

Creates a new Builder object with a content Uri.

UriMediaItem.Builder(Uri uri, Map<String, String> headers, List<HttpCookie> cookies)

Creates a new Builder object with a content Uri.

Public methods

UriMediaItem build()

Build MediaItem.

UriMediaItem.Builder setEndPosition(long position)

Sets the end position in milliseconds at which the playback will end.

UriMediaItem.Builder setMetadata(MediaMetadata metadata)

Set the metadata of this instance.

UriMediaItem.Builder setStartPosition(long position)

Sets the start position in milliseconds at which the playback will start.

Inherited methods

Public constructors

UriMediaItem.Builder

public UriMediaItem.Builder (Uri uri)

Creates a new Builder object with a content Uri.

Parameters
uri Uri: the Content URI of the data you want to play

UriMediaItem.Builder

public UriMediaItem.Builder (Uri uri, 
                Map<String, String> headers, 
                List<HttpCookie> cookies)

Creates a new Builder object with a content Uri. To provide cookies for the subsequent HTTP requests, you can install your own default cookie handler and use other variants of setMediaItem APIs instead.

Note that the cross domain redirection is allowed by default, but that can be changed with key/value pairs through the headers parameter with "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value to disallow or allow cross domain redirection.

Parameters
uri Uri: the Content URI of the data you want to play

headers Map: the headers to be sent together with the request for the data The headers must not include cookies. Instead, use the cookies param.

cookies List: the cookies to be sent together with the request

Throws
IllegalArgumentException if the cookie handler is not of CookieManager type when cookies are provided.

Public methods

build

public UriMediaItem build ()

Build MediaItem.

Returns
UriMediaItem A new UriMediaItem with values supplied by the Builder.

setEndPosition

public UriMediaItem.Builder setEndPosition (long position)

Sets the end position in milliseconds at which the playback will end. Any negative number is treated as maximum length of the media item.

Parameters
position long: the end position in milliseconds at which the playback will end

Returns
UriMediaItem.Builder this instance for chaining

setMetadata

public UriMediaItem.Builder setMetadata (MediaMetadata metadata)

Set the metadata of this instance. null for unset.

Parameters
metadata MediaMetadata: metadata

Returns
UriMediaItem.Builder this instance for chaining

setStartPosition

public UriMediaItem.Builder setStartPosition (long position)

Sets the start position in milliseconds at which the playback will start. Any negative number is treated as 0.

Parameters
position long: the start position in milliseconds at which the playback will start

Returns
UriMediaItem.Builder this instance for chaining