FileMediaItem.Builder

Added in 1.0.0
Deprecated in 1.3.0

public final class FileMediaItem.Builder extends 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 methods

@NonNull FileMediaItem
@NonNull FileMediaItem.Builder
setEndPosition(long position)

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

@NonNull FileMediaItem.Builder

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

@NonNull FileMediaItem.Builder

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

@NonNull FileMediaItem.Builder

Set the metadata of this instance.

@NonNull FileMediaItem.Builder
setStartPosition(long position)

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
public Builder(@NonNull 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 androidx.media2.player.MediaPlayer, androidx.media2.player.MediaPlayer will close the ParcelFileDescriptor.

Parameters
@NonNull ParcelFileDescriptor pfd

the ParcelFileDescriptor for the file you want to play

Public methods

build

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull FileMediaItem build()
Returns
@NonNull FileMediaItem

A new FileMediaItem with values supplied by the Builder.

setEndPosition

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull 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
long position

the end position in milliseconds at which the playback will end

Returns
@NonNull FileMediaItem.Builder

this instance for chaining

setFileDescriptorLength

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull 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
long length

the length of the data to be played in bytes

Returns
@NonNull FileMediaItem.Builder

this instance for chaining

setFileDescriptorOffset

Added in 1.0.0
Deprecated in 1.3.0
public @NonNull 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
long offset

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

Returns
@NonNull FileMediaItem.Builder

this instance for chaining

setMetadata

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull FileMediaItem.Builder setMetadata(@Nullable MediaMetadata metadata)

Set the metadata of this instance. null for unset.

Parameters
@Nullable MediaMetadata metadata

metadata

Returns
@NonNull FileMediaItem.Builder

this instance for chaining

setStartPosition

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull 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
long position

the start position in milliseconds at which the playback will start

Returns
@NonNull FileMediaItem.Builder

this instance for chaining