MediaItem
open class MediaItem : CustomVersionedParcelable
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 androidx.media2.session.MediaSession
/androidx.media2.session.MediaController
or androidx.media2.session.MediaLibraryService.MediaLibrarySession
/ androidx.media2.session.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. java.io.FileDescriptor
, android.content.Context
, etc).
This object is thread safe.
Summary
Nested classes | |
---|---|
open |
Builder for |
Constants | |
---|---|
static Long |
Used when a position is unknown. |
Public methods | |
---|---|
open Long |
Return the position in milliseconds at which the playback will end. |
open MediaMetadata? |
Gets the metadata of the media. |
open Long |
Return the position in milliseconds at which the playback will start. |
open Unit |
setMetadata(@Nullable metadata: MediaMetadata?) Sets metadata. |
open String |
toString() |
Constants
POSITION_UNKNOWN
static val POSITION_UNKNOWN: Long
Used when a position is unknown.
Value: LONG_MAX
See Also
Public methods
getEndPosition
open fun getEndPosition(): Long
Return the position in milliseconds at which the playback will end. POSITION_UNKNOWN
means ending at the end of source content.
Return | |
---|---|
Long |
the position in milliseconds at which the playback will end |
getMetadata
@Nullable open fun getMetadata(): MediaMetadata?
Gets the metadata of the media.
Return | |
---|---|
MediaMetadata? |
metadata from the session |
getStartPosition
open fun getStartPosition(): Long
Return the position in milliseconds at which the playback will start.
Return | |
---|---|
Long |
the position in milliseconds at which the playback will start |
setMetadata
open fun setMetadata(@Nullable 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 |
See Also
toString
open fun toString(): String