MediaItem

public class MediaItem
extends Object implements VersionedParcelable

java.lang.Object
   ↳ androidx.media2.common.MediaItem


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 MediaSession/MediaController or MediaLibraryService.MediaLibrarySession/ MediaBrowser, 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. FileDescriptor, Context, etc).

This object is thread safe.

Summary

Nested classes

class MediaItem.Builder

Builder for MediaItem

Constants

long POSITION_UNKNOWN

Used when a position is unknown.

Public methods

long getEndPosition()

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

MediaMetadata getMetadata()

Gets the metadata of the media.

long getStartPosition()

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

void setMetadata(MediaMetadata metadata)

Sets metadata.

String toString()

Inherited methods