belongs to Maven artifact androidx.media2:media2:1.0.0-alpha01

DataSourceDesc2.Builder

public static class DataSourceDesc2.Builder
extends Object

java.lang.Object
   ↳ androidx.media2.DataSourceDesc2.Builder


Builder class for DataSourceDesc2 objects.

Summary

Public constructors

DataSourceDesc2.Builder()

Constructs a new Builder with the defaults.

DataSourceDesc2.Builder(DataSourceDesc2 dsd)

Constructs a new Builder from a given DataSourceDesc2 instance

Public methods

DataSourceDesc2 build()

Combines all of the fields that have been set and return a new DataSourceDesc2 object.

DataSourceDesc2.Builder setDataSource(FileDescriptor fd)

Sets the data source (FileDescriptor) to use.

DataSourceDesc2.Builder setDataSource(FileDescriptor fd, long offset, long length)

Sets the data source (FileDescriptor) to use.

DataSourceDesc2.Builder setDataSource(Context context, Uri uri, Map<String, String> headers, List<HttpCookie> cookies)

Sets the data source as a content Uri.

DataSourceDesc2.Builder setDataSource(MediaDataSource2 m2ds)

Sets the data source (MediaDataSource2) to use.

DataSourceDesc2.Builder setDataSource(Context context, Uri uri)

Sets the data source as a content Uri.

DataSourceDesc2.Builder setEndPosition(long position)

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

DataSourceDesc2.Builder setMediaId(String mediaId)

Sets the media Id of this data source.

DataSourceDesc2.Builder setStartPosition(long position)

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

Inherited methods

Public constructors

DataSourceDesc2.Builder

public DataSourceDesc2.Builder ()

Constructs a new Builder with the defaults.

DataSourceDesc2.Builder

public DataSourceDesc2.Builder (DataSourceDesc2 dsd)

Constructs a new Builder from a given DataSourceDesc2 instance

Parameters
dsd DataSourceDesc2: the DataSourceDesc2 object whose data will be reused in the new Builder.

Public methods

build

public DataSourceDesc2 build ()

Combines all of the fields that have been set and return a new DataSourceDesc2 object. IllegalStateException will be thrown if there is conflict between fields.

Returns
DataSourceDesc2 a new DataSourceDesc2 object

setDataSource

public DataSourceDesc2.Builder setDataSource (FileDescriptor fd)

Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor after the source has been used.

Parameters
fd FileDescriptor: the FileDescriptor for the file you want to play

Returns
DataSourceDesc2.Builder the same Builder instance.

Throws
NullPointerException if fd is null.

setDataSource

public DataSourceDesc2.Builder setDataSource (FileDescriptor fd, 
                long offset, 
                long length)

Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor after the source has been used. Any negative number for offset is treated as 0. Any negative number for length is treated as maximum length of the data source.

Parameters
fd FileDescriptor: the FileDescriptor for the file you want to play

offset long: the offset into the file where the data to be played starts, in bytes

length long: the length in bytes of the data to be played

Returns
DataSourceDesc2.Builder the same Builder instance.

Throws
NullPointerException if fd is null.

setDataSource

public DataSourceDesc2.Builder setDataSource (Context context, 
                Uri uri, 
                Map<String, String> headers, 
                List<HttpCookie> cookies)

Sets the data source as a content Uri. To provide cookies for the subsequent HTTP requests, you can install your own default cookie handler and use other variants of setDataSource 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
context Context: the Context to use when resolving the Uri

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

Returns
DataSourceDesc2.Builder the same Builder instance.

Throws
NullPointerException if context or uri is null.
IllegalArgumentException if the cookie handler is not of CookieManager type when cookies are provided.

setDataSource

public DataSourceDesc2.Builder setDataSource (MediaDataSource2 m2ds)

Sets the data source (MediaDataSource2) to use.

Parameters
m2ds MediaDataSource2: the MediaDataSource2 for the media you want to play

Returns
DataSourceDesc2.Builder the same Builder instance.

Throws
NullPointerException if m2ds is null.

setDataSource

public DataSourceDesc2.Builder setDataSource (Context context, 
                Uri uri)

Sets the data source as a content Uri.

Parameters
context Context: the Context to use when resolving the Uri

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

Returns
DataSourceDesc2.Builder the same Builder instance.

Throws
NullPointerException if context or uri is null.

setEndPosition

public DataSourceDesc2.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 data source.

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

Returns
DataSourceDesc2.Builder the same Builder instance.

setMediaId

public DataSourceDesc2.Builder setMediaId (String mediaId)

Sets the media Id of this data source.

Parameters
mediaId String: the media Id of this data source

Returns
DataSourceDesc2.Builder the same Builder instance.

setStartPosition

public DataSourceDesc2.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
DataSourceDesc2.Builder the same Builder instance.