FileDocCategorySizeDatePackage
MediaSessionStatus.javaAPI DocAndroid 5.1 API8243Thu Mar 12 22:22:56 GMT 2015android.support.v7.media

MediaSessionStatus

public final class MediaSessionStatus extends Object
Describes the playback status of a media session.

This class is part of the remote playback protocol described by the {@link MediaControlIntent MediaControlIntent} class.

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

To monitor session status, the application should supply a {@link PendingIntent} to use as the {@link MediaControlIntent#EXTRA_SESSION_STATUS_UPDATE_RECEIVER session status update receiver} for a given {@link MediaControlIntent#ACTION_START_SESSION session start request}.

This object is immutable once created using a {@link Builder} instance.

Fields Summary
private static final String
KEY_TIMESTAMP
private static final String
KEY_SESSION_STATE
private static final String
KEY_QUEUE_PAUSED
private static final String
KEY_EXTRAS
private final android.os.Bundle
mBundle
public static final int
SESSION_STATE_ACTIVE
Session state: Active.

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

public static final int
SESSION_STATE_ENDED
Session state: Ended.

Indicates that the media session was ended normally using the {@link MediaControlIntent#ACTION_END_SESSION end session} action.

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

public static final int
SESSION_STATE_INVALIDATED
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.

Constructors Summary
private MediaSessionStatus(android.os.Bundle bundle)


       
        mBundle = bundle;
    
Methods Summary
public android.os.BundleasBundle()
Converts this object to a bundle for serialization.

return
The contents of the object represented as a bundle.

        return mBundle;
    
public static android.support.v7.media.MediaSessionStatusfromBundle(android.os.Bundle bundle)
Creates an instance from a bundle.

param
bundle The bundle, or null if none.
return
The new instance, or null if the bundle was null.

        return bundle != null ? new MediaSessionStatus(bundle) : null;
    
public android.os.BundlegetExtras()
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.

        return mBundle.getBundle(KEY_EXTRAS);
    
public intgetSessionState()
Gets the session state.

return
The session state. One of {@link #SESSION_STATE_ACTIVE}, {@link #SESSION_STATE_ENDED}, or {@link #SESSION_STATE_INVALIDATED}.

        return mBundle.getInt(KEY_SESSION_STATE, SESSION_STATE_INVALIDATED);
    
public longgetTimestamp()
Gets the timestamp associated with the status information in milliseconds since boot in the {@link SystemClock#elapsedRealtime} time base.

return
The status timestamp in the {@link SystemClock#elapsedRealtime()} time base.

        return mBundle.getLong(KEY_TIMESTAMP);
    
public booleanisQueuePaused()
Returns true if the session's queue is paused.

return
True if the session's queue is paused.

        return mBundle.getBoolean(KEY_QUEUE_PAUSED);
    
private static java.lang.StringsessionStateToString(int sessionState)

        switch (sessionState) {
            case SESSION_STATE_ACTIVE:
                return "active";
            case SESSION_STATE_ENDED:
                return "ended";
            case SESSION_STATE_INVALIDATED:
                return "invalidated";
        }
        return Integer.toString(sessionState);
    
public java.lang.StringtoString()

        StringBuilder result = new StringBuilder();
        result.append("MediaSessionStatus{ ");
        result.append("timestamp=");
        TimeUtils.formatDuration(SystemClock.elapsedRealtime() - getTimestamp(), result);
        result.append(" ms ago");
        result.append(", sessionState=").append(sessionStateToString(getSessionState()));
        result.append(", queuePaused=").append(isQueuePaused());
        result.append(", extras=").append(getExtras());
        result.append(" }");
        return result.toString();