The Android Developer Challenge is back! Submit your idea before December 2.

FileMediaItem.Builder

public static final class FileMediaItem.Builder
extends MediaItem.Builder

java.lang.Object
   ↳ androidx.media2.common.MediaItem.Builder
     ↳ androidx.media2.common.FileMediaItem.Builder


This Builder class simplifies the creation of a FileMediaItem object.

Summary

Public constructors

FileMediaItem.Builder(ParcelFileDescriptor pfd)

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

Public methods

FileMediaItem build()

Build MediaItem.

FileMediaItem.Builder setEndPosition(long position)

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

FileMediaItem.Builder setFileDescriptorLength(long length)

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

FileMediaItem.Builder setFileDescriptorOffset(long offset)

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

FileMediaItem.Builder setMetadata(MediaMetadata metadata)

Set the metadata of this instance.

FileMediaItem.Builder setStartPosition(long position)

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

Inherited methods

Public constructors

FileMediaItem.Builder

public FileMediaItem.Builder (ParcelFileDescriptor pfd)

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 MediaPlayer, MediaPlayer will close the ParcelFileDescriptor.

Parameters
pfd ParcelFileDescriptor: the ParcelFileDescriptor for the file you want to play

Public methods

build

public FileMediaItem build ()

Build MediaItem.

Returns
FileMediaItem A new FileMediaItem with values supplied by the Builder.

setEndPosition

public FileMediaItem.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 media item.

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

Returns
FileMediaItem.Builder this instance for chaining

setFileDescriptorLength

public FileMediaItem.Builder setFileDescriptorLength (long length)

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

public FileMediaItem.Builder setFileDescriptorOffset (long offset)

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

public FileMediaItem.Builder setMetadata (MediaMetadata metadata)

Set the metadata of this instance. null for unset.

Parameters
metadata MediaMetadata: metadata

Returns
FileMediaItem.Builder this instance for chaining

setStartPosition

public FileMediaItem.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
FileMediaItem.Builder this instance for chaining