Builder

class Builder
kotlin.Any
   ↳ androidx.media.DataSourceDesc.Builder

Builder class for DataSourceDesc objects.

Summary

Public constructors

Constructs a new Builder with the defaults.

Constructs a new Builder from a given DataSourceDesc instance

Public methods
open DataSourceDesc.Builder
setMediaId(mediaId: String!)

Sets the media Id of this data source.

open DataSourceDesc.Builder
setEndPosition(position: Long)

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

open DataSourceDesc.Builder

Sets the data source (Media2DataSource) to use.

open DataSourceDesc.Builder

Sets the data source (FileDescriptor) to use.

open DataSourceDesc.Builder
setDataSource(fd: FileDescriptor, offset: Long, length: Long)

Sets the data source (FileDescriptor) to use.

open DataSourceDesc.Builder
setDataSource(context: Context, uri: Uri)

Sets the data source as a content Uri.

open DataSourceDesc.Builder
setDataSource(context: Context, uri: Uri, headers: MutableMap<String!, String!>?, cookies: MutableList<HttpCookie!>?)

Sets the data source as a content Uri.

open DataSourceDesc.Builder

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

open DataSourceDesc

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

Public constructors

<init>

Builder()

Constructs a new Builder with the defaults.

<init>

Builder(dsd: DataSourceDesc)

Constructs a new Builder from a given DataSourceDesc instance

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

Public methods

setMediaId

open fun setMediaId(mediaId: String!): DataSourceDesc.Builder

Sets the media Id of this data source.

Parameters
mediaId String!: the media Id of this data source
Return
DataSourceDesc.Builder: the same Builder instance.

setEndPosition

open fun setEndPosition(position: Long): DataSourceDesc.Builder

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
Return
DataSourceDesc.Builder: the same Builder instance.

setDataSource

open fun setDataSource(m2ds: Media2DataSource): DataSourceDesc.Builder

Sets the data source (Media2DataSource) to use.

Parameters
m2ds Media2DataSource: the Media2DataSource for the media you want to play
Return
DataSourceDesc.Builder: the same Builder instance.
Exceptions
NullPointerException if m2ds is null.

setDataSource

open fun setDataSource(fd: FileDescriptor): DataSourceDesc.Builder

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
Return
DataSourceDesc.Builder: the same Builder instance.
Exceptions
NullPointerException if fd is null.

setDataSource

open fun setDataSource(fd: FileDescriptor, offset: Long, length: Long): DataSourceDesc.Builder

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 FileDescriptor: the offset into the file where the data to be played starts, in bytes
length FileDescriptor: the length in bytes of the data to be played
Return
DataSourceDesc.Builder: the same Builder instance.
Exceptions
NullPointerException if fd is null.

setDataSource

open fun setDataSource(context: Context, uri: Uri): DataSourceDesc.Builder

Sets the data source as a content Uri.

Parameters
context Context: the Context to use when resolving the Uri
uri Context: the Content URI of the data you want to play
Return
DataSourceDesc.Builder: the same Builder instance.
Exceptions
NullPointerException if context or uri is null.

setDataSource

open fun setDataSource(context: Context, uri: Uri, headers: MutableMap<String!, String!>?, cookies: MutableList<HttpCookie!>?): DataSourceDesc.Builder

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 Context: the Content URI of the data you want to play
headers Context: the headers to be sent together with the request for the data The headers must not include cookies. Instead, use the cookies param.
cookies Context: the cookies to be sent together with the request
Return
DataSourceDesc.Builder: the same Builder instance.
Exceptions
NullPointerException if context or uri is null.
IllegalArgumentException if the cookie handler is not of CookieManager type when cookies are provided.

setStartPosition

open fun setStartPosition(position: Long): DataSourceDesc.Builder

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
Return
DataSourceDesc.Builder: the same Builder instance.

build

open fun build(): DataSourceDesc

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

Return
DataSourceDesc: a new DataSourceDesc object