Add extras to the PlaybackState

This allows apps to include extras that are atomic with play state
changes.

bug:18189125
bug:18103891
Change-Id: Ia3bc5b0dcf29960cb70e2ff3a67ec1fdd48b7a5a
This commit is contained in:
RoboErik
2014-11-04 13:47:45 -08:00
parent 566c1ed18f
commit 131e63adaa
2 changed files with 33 additions and 4 deletions

View File

@@ -16363,6 +16363,7 @@ package android.media.session {
method public long getBufferedPosition();
method public java.util.List<android.media.session.PlaybackState.CustomAction> getCustomActions();
method public java.lang.CharSequence getErrorMessage();
method public android.os.Bundle getExtras();
method public long getLastPositionUpdateTime();
method public float getPlaybackSpeed();
method public long getPosition();
@@ -16407,6 +16408,7 @@ package android.media.session {
method public android.media.session.PlaybackState.Builder setActiveQueueItemId(long);
method public android.media.session.PlaybackState.Builder setBufferedPosition(long);
method public android.media.session.PlaybackState.Builder setErrorMessage(java.lang.CharSequence);
method public android.media.session.PlaybackState.Builder setExtras(android.os.Bundle);
method public android.media.session.PlaybackState.Builder setState(int, long, float, long);
method public android.media.session.PlaybackState.Builder setState(int, long, float);
}

View File

@@ -16,6 +16,7 @@
package android.media.session;
import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.media.RemoteControlClient;
import android.os.Bundle;
import android.os.Parcel;
@@ -232,11 +233,12 @@ public final class PlaybackState implements Parcelable {
private final CharSequence mErrorMessage;
private final long mUpdateTime;
private final long mActiveItemId;
private final Bundle mExtras;
private PlaybackState(int state, long position, long updateTime, float speed,
long bufferedPosition, long transportControls,
List<PlaybackState.CustomAction> customActions, long activeItemId,
CharSequence error) {
CharSequence error, Bundle extras) {
mState = state;
mPosition = position;
mSpeed = speed;
@@ -246,6 +248,7 @@ public final class PlaybackState implements Parcelable {
mCustomActions = new ArrayList<>(customActions);
mActiveItemId = activeItemId;
mErrorMessage = error;
mExtras = extras;
}
private PlaybackState(Parcel in) {
@@ -258,7 +261,7 @@ public final class PlaybackState implements Parcelable {
mCustomActions = in.createTypedArrayList(CustomAction.CREATOR);
mActiveItemId = in.readLong();
mErrorMessage = in.readCharSequence();
mExtras = in.readBundle();
}
@Override
@@ -293,6 +296,7 @@ public final class PlaybackState implements Parcelable {
dest.writeTypedList(mCustomActions);
dest.writeLong(mActiveItemId);
dest.writeCharSequence(mErrorMessage);
dest.writeBundle(mExtras);
}
/**
@@ -394,6 +398,15 @@ public final class PlaybackState implements Parcelable {
return mActiveItemId;
}
/**
* Get any custom extras that were set on this playback state.
*
* @return The extras for this state or null.
*/
public @Nullable Bundle getExtras() {
return mExtras;
}
/**
* Get the {@link PlaybackState} state for the given
* {@link RemoteControlClient} state.
@@ -738,6 +751,7 @@ public final class PlaybackState implements Parcelable {
private CharSequence mErrorMessage;
private long mUpdateTime;
private long mActiveItemId = MediaSession.QueueItem.UNKNOWN_ID;
private Bundle mExtras;
/**
* Creates an initially empty state builder.
@@ -766,6 +780,7 @@ public final class PlaybackState implements Parcelable {
mErrorMessage = from.mErrorMessage;
mUpdateTime = from.mUpdateTime;
mActiveItemId = from.mActiveItemId;
mExtras = from.mExtras;
}
/**
@@ -948,13 +963,25 @@ public final class PlaybackState implements Parcelable {
}
/**
* Build and return the {@link PlaybackState} instance with these values.
* Set any custom extras to be included with the playback state.
*
* @param extras The extras to include.
* @return this
*/
public Builder setExtras(Bundle extras) {
mExtras = extras;
return this;
}
/**
* Build and return the {@link PlaybackState} instance with these
* values.
*
* @return A new state instance.
*/
public PlaybackState build() {
return new PlaybackState(mState, mPosition, mUpdateTime, mSpeed, mBufferedPosition,
mActions, mCustomActions, mActiveItemId, mErrorMessage);
mActions, mCustomActions, mActiveItemId, mErrorMessage, mExtras);
}
}
}