FileMediaItem.Builder

Added in 1.0.0
Deprecated in 1.3.0

class FileMediaItem.Builder : MediaItem.Builder


This Builder class simplifies the creation of a FileMediaItem object.

Summary

Public constructors

Creates a new Builder object with a media item (ParcelFileDescriptor) to use.

Public functions

FileMediaItem
FileMediaItem.Builder
setEndPosition(position: Long)

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

FileMediaItem.Builder

Sets the length of the data to be played in bytes.

FileMediaItem.Builder

Sets the start offset of the file where the data to be played in bytes.

FileMediaItem.Builder

Set the metadata of this instance.

FileMediaItem.Builder

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

Public constructors

Builder

Added in 1.0.0
Deprecated in 1.3.0
Builder(pfd: ParcelFileDescriptor)

Creates a new Builder object with a media item (ParcelFileDescriptor) to use. The ParcelFileDescriptor must be seekable (N.B. a LocalSocket is not seekable).

If FileMediaItem is passed to androidx.media2.player.MediaPlayer, androidx.media2.player.MediaPlayer will close the ParcelFileDescriptor.

Parameters
pfd: ParcelFileDescriptor

the ParcelFileDescriptor for the file you want to play

Public functions

build

Added in 1.3.0
Deprecated in 1.3.0
fun build(): FileMediaItem
Returns
FileMediaItem

A new FileMediaItem with values supplied by the Builder.

setEndPosition

Added in 1.3.0
Deprecated in 1.3.0
fun setEndPosition(position: Long): FileMediaItem.Builder

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
FileMediaItem.Builder

this instance for chaining

setFileDescriptorLength

Added in 1.0.0
Deprecated in 1.3.0
fun setFileDescriptorLength(length: Long): FileMediaItem.Builder

Sets the length of the data to be played in bytes. Any negative number for length is treated as maximum length of the media item.

Parameters
length: Long

the length of the data to be played in bytes

Returns
FileMediaItem.Builder

this instance for chaining

setFileDescriptorOffset

Added in 1.0.0
Deprecated in 1.3.0
fun setFileDescriptorOffset(offset: Long): FileMediaItem.Builder

Sets the start offset of the file where the data to be played in bytes. Any negative number for offset is treated as 0.

Parameters
offset: Long

the start offset of the file where the data to be played in bytes

Returns
FileMediaItem.Builder

this instance for chaining

setMetadata

Added in 1.3.0
Deprecated in 1.3.0
fun setMetadata(metadata: MediaMetadata?): FileMediaItem.Builder

Set the metadata of this instance. null for unset.

Parameters
metadata: MediaMetadata?

metadata

Returns
FileMediaItem.Builder

this instance for chaining

setStartPosition

Added in 1.3.0
Deprecated in 1.3.0
fun setStartPosition(position: Long): FileMediaItem.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

Returns
FileMediaItem.Builder

this instance for chaining