Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

FileMediaItem.Builder

public static final class FileMediaItem.Builder
extends Object

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


This Builder class simplifies the creation of a FileMediaItem object.

Summary

Public constructors

FileMediaItem.Builder(FileDescriptor fd)

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

FileMediaItem.Builder(FileDescriptor fd, long offset, long length)

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

Public methods

FileMediaItem build()

Build MediaItem.

T extends BuilderBase setEndPosition(long position)

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

T extends BuilderBase setMetadata(MediaMetadata metadata)

Set the metadata of this instance.

T extends BuilderBase setStartPosition(long position)

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

Inherited methods

Public constructors

FileMediaItem.Builder

public FileMediaItem.Builder (FileDescriptor fd)

Creates a new Builder object with a media item (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor after the source has been used.

Parameters
fd FileDescriptor: the FileDescriptor for the file you want to play

FileMediaItem.Builder

public FileMediaItem.Builder (FileDescriptor fd, 
                long offset, 
                long length)

Creates a new Builder object with a media item (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor after the source has been used. Any negative number for offset is treated as 0. Any negative number for length is treated as maximum length of the media item.

Parameters
fd FileDescriptor: the FileDescriptor for the file you want to play

offset long: the offset into the file where the data to be played starts, in bytes

length long: the length in bytes of the data to be played

Public methods

build

public FileMediaItem build ()

Build MediaItem.

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

setEndPosition

public T extends BuilderBase 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
T extends BuilderBase the same Builder instance.

setMetadata

public T extends BuilderBase setMetadata (MediaMetadata metadata)

Set the metadata of this instance. null for unset.

Parameters
metadata MediaMetadata: metadata

Returns
T extends BuilderBase this instance for chaining

setStartPosition

public T extends BuilderBase 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
T extends BuilderBase the same Builder instance.