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

Builder

class Builder : MediaItem.Builder
kotlin.Any
   ↳ androidx.media2.common.MediaItem.Builder
   ↳ androidx.media2.common.UriMediaItem.Builder

This Builder class simplifies the creation of a UriMediaItem object.

Summary

Public constructors

<init>(@NonNull uri: Uri)

Creates a new Builder object with a content Uri.

<init>(@NonNull uri: Uri, @Nullable headers: MutableMap<String!, String!>?, @Nullable cookies: MutableList<HttpCookie!>?)

Creates a new Builder object with a content Uri.

Public methods

UriMediaItem

UriMediaItem.Builder
setEndPosition(position: Long)

UriMediaItem.Builder
setMetadata(@Nullable metadata: MediaMetadata?)

UriMediaItem.Builder

Public constructors

<init>

Builder(@NonNull uri: Uri)

Creates a new Builder object with a content Uri.

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

<init>

Builder(@NonNull uri: Uri, @Nullable headers: MutableMap<String!, String!>?, @Nullable cookies: MutableList<HttpCookie!>?)

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 Uri: the headers to be sent together with the request for the data The headers must not include cookies. Instead, use the cookies param.
cookies Uri: the cookies to be sent together with the request
Exceptions
IllegalArgumentException if the cookie handler is not of CookieManager type when cookies are provided.

Public methods

build

@NonNull fun build(): UriMediaItem
Return
UriMediaItem: A new UriMediaItem with values supplied by the Builder.

setEndPosition

@NonNull fun setEndPosition(position: Long): UriMediaItem.Builder

setMetadata

@NonNull fun setMetadata(@Nullable metadata: MediaMetadata?): UriMediaItem.Builder

setStartPosition

@NonNull fun setStartPosition(position: Long): UriMediaItem.Builder