Register now for Android Dev Summit 2019!

Builder

class Builder : MediaItem.Builder
kotlin.Any
   ↳ androidx.media2.common.MediaItem.Builder
   ↳ androidx.media2.common.FileMediaItem.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 methods

FileMediaItem

FileMediaItem.Builder
setEndPosition(position: Long)

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
setMetadata(@Nullable metadata: MediaMetadata?)

FileMediaItem.Builder

Public constructors

<init>

Builder(@NonNull 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 methods

build

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

setEndPosition

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

setFileDescriptorLength

@NonNull 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
Return
FileMediaItem.Builder: this instance for chaining

setFileDescriptorOffset

@NonNull 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
Return
FileMediaItem.Builder: this instance for chaining

setMetadata

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

setStartPosition

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