MediaSessionStatus


public final class MediaSessionStatus


Describes the playback status of a media session.

This class is part of the remote playback protocol described by the MediaControlIntent class.

When a media session is created, it is initially in the active state. When the media session ends normally, it transitions to the ended state. If the media session is invalidated due to another session forcibly taking control of the route, then it transitions to the invalidated state. Refer to the documentation of each state for an explanation of its meaning.

To monitor session status, the application should supply a PendingIntent to use as the session status update receiver for a given session start request.

This object is immutable once created using a Builder instance.

Summary

Nested types

public final class MediaSessionStatus.Builder

Builder for media session status objects.

Constants

static final int

Session state: Active.

static final int

Session state: Ended.

static final int

Session state: Invalidated.

Public methods

@NonNull Bundle

Converts this object to a bundle for serialization.

static @Nullable MediaSessionStatus

Creates an instance from a bundle.

@Nullable Bundle

Gets a bundle of extras for this status object.

int

Gets the session state.

long

Gets the timestamp associated with the status information in milliseconds since boot in the elapsedRealtime time base.

boolean

Returns true if the session's queue is paused.

@NonNull String

Constants

SESSION_STATE_ACTIVE

Added in 1.1.0
public static final int SESSION_STATE_ACTIVE = 0

Session state: Active.

Indicates that the media session is active and in control of the route.

SESSION_STATE_ENDED

Added in 1.1.0
public static final int SESSION_STATE_ENDED = 1

Session state: Ended.

Indicates that the media session was ended normally using the end session action.

A terminated media session cannot be used anymore. To play more media, the application must start a new session.

SESSION_STATE_INVALIDATED

Added in 1.1.0
public static final int SESSION_STATE_INVALIDATED = 2

Session state: Invalidated.

Indicates that the media session was invalidated involuntarily due to another session taking control of the route.

An invalidated media session cannot be used anymore. To play more media, the application must start a new session.

Public methods

asBundle

Added in 1.1.0
public @NonNull Bundle asBundle()

Converts this object to a bundle for serialization.

Returns
@NonNull Bundle

The contents of the object represented as a bundle.

fromBundle

Added in 1.1.0
public static @Nullable MediaSessionStatus fromBundle(@Nullable Bundle bundle)

Creates an instance from a bundle.

Parameters
@Nullable Bundle bundle

The bundle, or null if none.

Returns
@Nullable MediaSessionStatus

The new instance, or null if the bundle was null.

getExtras

Added in 1.1.0
public @Nullable Bundle getExtras()

Gets a bundle of extras for this status object. The extras will be ignored by the media router but they may be used by applications.

getSessionState

Added in 1.1.0
public int getSessionState()

Gets the session state.

Returns
int

The session state. One of SESSION_STATE_ACTIVE, SESSION_STATE_ENDED, or SESSION_STATE_INVALIDATED.

getTimestamp

Added in 1.1.0
public long getTimestamp()

Gets the timestamp associated with the status information in milliseconds since boot in the elapsedRealtime time base.

Returns
long

The status timestamp in the elapsedRealtime time base.

isQueuePaused

Added in 1.1.0
public boolean isQueuePaused()

Returns true if the session's queue is paused.

Returns
boolean

True if the session's queue is paused.

toString

public @NonNull String toString()