MediaService

interface MediaService

Media service.

This service provides:

A media source is an app which has registered a MediaBrowserServiceCompat (from androidx.media), and is able to play content and lets clients browse it.

This service concentrates all information about media currently being played. As only one source at a time can play audio, Android decides which one gets the audio focus. The chosen source is available here as activeSource.

Each media source makes different operations (actions) available at any given time to be performed, or launched, on the media that it is currently being played. Action represents such an action, and availableActions is a list of what actions are presently available.

Browsing through media offered by media sources is possible with a SourceClient. The IVI media service intentionally excludes this functionality to concentrate on the playback state.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val activeMediaItem: IviMediaItem?

Information about the currently active media item of the activeSource. Can be null if there is no active media or if there is no active source.

Link copied to clipboard
abstract val activeQueue: List<IviMediaItem>

The queue of media items that are currently scheduled for playing by the activeSource. Can be empty if no queue is specified or if there is no active source.

Link copied to clipboard
abstract val activeQueueItemIndex: Int?

Index of the item in activeQueue that is currently being played. Can be null if there is no active media, if the queue is empty, or if there is no active source.

Link copied to clipboard
abstract val activeSource: SourceInfo?

Which source is currently active. The active source is the one almost all of the information provided by the MediaService refers to. Can be null if there is no active source.

Link copied to clipboard
abstract val availableActions: List<Action>

Actions provided by the activeSource for the activeMediaItem.

Link copied to clipboard
abstract val isBuffering: Boolean

Whether the playback is stalled because of buffering.

Link copied to clipboard
abstract val playbackState: IviPlaybackState

Playback state of the media currently being played by the activeSource. IviPlaybackState.IDLE if nothing is being played, or if there is no active source.

Link copied to clipboard
abstract val playbackTimeInfo: MediaPlaybackTimeInfo?

Time information of the media currently being played, such as the current position. Is null if nothing is being played.

Link copied to clipboard
abstract val sources: List<SourceInfo>

Media sources currently registered in the system. Service users will be notified (via LiveData update) when sources change, usually happening when the APK of a source is installed or uninstalled, or when a source requires the user to log in.

Functions

Link copied to clipboard
abstract suspend fun getActiveMediaItemFromSource(sourceId: SourceId): IviMediaItem?

Returns the active media item for the given sourceId. Returns null if the specified source does not have any active IviMediaItem. To get the active media of the activeSource, just use activeMediaItem directly.

Link copied to clipboard
abstract suspend fun launchAction(action: Action)

Issues a Action to the current media source.