MediaItem

Added in 1.0.0
Deprecated in 1.3.0

public class MediaItem implements VersionedParcelable

Known direct subclasses
CallbackMediaItem

This class is deprecated.

androidx.media2 is deprecated.

FileMediaItem

This class is deprecated.

androidx.media2 is deprecated.

UriMediaItem

This class is deprecated.

androidx.media2 is deprecated.


A class with information on a single media item with the metadata information. Here are use cases.

  • Specify media items to SessionPlayer for playback.
  • Share media items across the processes.

Subclasses of the session player may only accept certain subclasses of the media items. Check the player documentation that you're interested in.

When it's shared across the processes, we cannot guarantee that they contain the right values because media items are application dependent especially for the metadata.

When an object of the MediaItem's subclass is sent across the process between /androidx.media2.session.MediaController or / , the object will sent as if it's MediaItem. The recipient cannot get the object with the subclasses' type. This will sanitize process specific information (e.g. java.io.FileDescriptor, android.content.Context, etc).

This object is thread safe.

Summary

Nested types

public class MediaItem.Builder

This class is deprecated.

androidx.media2 is deprecated.

Constants

static final long
POSITION_UNKNOWN = 576460752303423487

Used when a position is unknown.

Public methods

long

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

@Nullable MediaMetadata

Gets the metadata of the media.

long

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

void

Sets metadata.

String

Constants

POSITION_UNKNOWN

Added in 1.0.0
Deprecated in 1.3.0
public static final long POSITION_UNKNOWN = 576460752303423487

Used when a position is unknown.

See also
getEndPosition

Public methods

getEndPosition

Added in 1.0.0
Deprecated in 1.3.0
public long getEndPosition()

Return the position in milliseconds at which the playback will end. POSITION_UNKNOWN means ending at the end of source content.

Returns
long

the position in milliseconds at which the playback will end

getMetadata

Added in 1.0.0
Deprecated in 1.3.0
public @Nullable MediaMetadata getMetadata()

Gets the metadata of the media.

Returns
@Nullable MediaMetadata

metadata from the session

getStartPosition

Added in 1.0.0
Deprecated in 1.3.0
public long getStartPosition()

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

Returns
long

the position in milliseconds at which the playback will start

setMetadata

Added in 1.0.0
Deprecated in 1.3.0
public void setMetadata(@Nullable MediaMetadata metadata)

Sets metadata. If the metadata is not null, its id should be matched with this instance's media id.

Parameters
@Nullable MediaMetadata metadata

metadata to update

toString

public String toString()