MediaItem

Added in 1.0.0
Deprecated in 1.3.0

class MediaItem : 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

This class is deprecated.

androidx.media2 is deprecated.

Constants

const Long
POSITION_UNKNOWN = 576460752303423487

Used when a position is unknown.

Public functions

Long

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

MediaMetadata?

Gets the metadata of the media.

Long

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

Unit

Sets metadata.

String!

Constants

POSITION_UNKNOWN

Added in 1.0.0
Deprecated in 1.3.0
const val POSITION_UNKNOWN = 576460752303423487: Long

Used when a position is unknown.

See also
getEndPosition

Public functions

getEndPosition

Added in 1.0.0
Deprecated in 1.3.0
fun getEndPosition(): Long

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
fun getMetadata(): MediaMetadata?

Gets the metadata of the media.

Returns
MediaMetadata?

metadata from the session

getStartPosition

Added in 1.0.0
Deprecated in 1.3.0
fun getStartPosition(): Long

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
fun setMetadata(metadata: MediaMetadata?): Unit

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

Parameters
metadata: MediaMetadata?

metadata to update

toString

fun toString(): String!