public final class

FileMediaItem.Builder

extends MediaItem.Builder

 java.lang.Object

androidx.media2.common.MediaItem.Builder

↳androidx.media2.common.FileMediaItem.Builder

Overview

This Builder class simplifies the creation of a FileMediaItem object.

Summary

Constructors
publicBuilder(ParcelFileDescriptor pfd)

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

Methods
public FileMediaItembuild()

public MediaItem.BuildersetEndPosition(long position)

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

public FileMediaItem.BuildersetFileDescriptorLength(long length)

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

public FileMediaItem.BuildersetFileDescriptorOffset(long offset)

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

public MediaItem.BuildersetMetadata(MediaMetadata metadata)

Set the metadata of this instance.

public MediaItem.BuildersetStartPosition(long position)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public 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: the ParcelFileDescriptor for the file you want to play

Methods

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: the start offset of the file where the data to be played in bytes

Returns:

this instance for chaining

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: the length of the data to be played in bytes

Returns:

this instance for chaining

public MediaItem.Builder setMetadata(MediaMetadata metadata)

Set the metadata of this instance. null for unset.

Parameters:

metadata: metadata

Returns:

this instance for chaining

public MediaItem.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: the start position in milliseconds at which the playback will start

Returns:

this instance for chaining

public MediaItem.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: the end position in milliseconds at which the playback will end

Returns:

this instance for chaining

public FileMediaItem build()

Returns:

A new FileMediaItem with values supplied by the Builder.