Methods Summary |
---|
private void | addCallbackLocked(android.media.session.MediaController$Callback cb, android.os.Handler handler)
if (getHandlerForCallbackLocked(cb) != null) {
Log.w(TAG, "Callback is already added, ignoring");
return;
}
MessageHandler holder = new MessageHandler(handler.getLooper(), cb);
mCallbacks.add(holder);
holder.mRegistered = true;
if (!mCbRegistered) {
try {
mSessionBinder.registerCallbackListener(mCbStub);
mCbRegistered = true;
} catch (RemoteException e) {
Log.e(TAG, "Dead object in registerCallback", e);
}
}
|
public void | adjustVolume(int direction, int flags)Adjust the volume of the output this session is playing on. The direction
must be one of {@link AudioManager#ADJUST_LOWER},
{@link AudioManager#ADJUST_RAISE}, or {@link AudioManager#ADJUST_SAME}.
The command will be ignored if the session does not support
{@link VolumeProvider#VOLUME_CONTROL_RELATIVE} or
{@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}. The flags in
{@link AudioManager} may be used to affect the handling.
try {
mSessionBinder.adjustVolume(direction, flags, mContext.getPackageName());
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
}
|
public boolean | controlsSameSession(android.media.session.MediaController other)
if (other == null) return false;
return mSessionBinder.asBinder() == other.getSessionBinder().asBinder();
|
public boolean | dispatchMediaButtonEvent(android.view.KeyEvent keyEvent)Send the specified media button event to the session. Only media keys can
be sent by this method, other keys will be ignored.
if (keyEvent == null) {
throw new IllegalArgumentException("KeyEvent may not be null");
}
if (!KeyEvent.isMediaKey(keyEvent.getKeyCode())) {
return false;
}
try {
return mSessionBinder.sendMediaButton(keyEvent);
} catch (RemoteException e) {
// System is dead. =(
}
return false;
|
public android.os.Bundle | getExtras()Get the extras for this session.
try {
return mSessionBinder.getExtras();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getExtras", e);
}
return null;
|
public long | getFlags()Get the flags for this session. Flags are defined in {@link MediaSession}.
try {
return mSessionBinder.getFlags();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getFlags.", e);
}
return 0;
|
private android.media.session.MediaController$MessageHandler | getHandlerForCallbackLocked(android.media.session.MediaController$Callback cb)
if (cb == null) {
throw new IllegalArgumentException("Callback cannot be null");
}
for (int i = mCallbacks.size() - 1; i >= 0; i--) {
MessageHandler handler = mCallbacks.get(i);
if (cb == handler.mCallback) {
return handler;
}
}
return null;
|
public android.media.MediaMetadata | getMetadata()Get the current metadata for this session.
try {
return mSessionBinder.getMetadata();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getMetadata.", e);
return null;
}
|
public java.lang.String | getPackageName()Get the session owner's package name.
if (mPackageName == null) {
try {
mPackageName = mSessionBinder.getPackageName();
} catch (RemoteException e) {
Log.d(TAG, "Dead object in getPackageName.", e);
}
}
return mPackageName;
|
public android.media.session.MediaController$PlaybackInfo | getPlaybackInfo()Get the current playback info for this session.
try {
ParcelableVolumeInfo result = mSessionBinder.getVolumeAttributes();
return new PlaybackInfo(result.volumeType, result.audioAttrs, result.controlType,
result.maxVolume, result.currentVolume);
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getAudioInfo.", e);
}
return null;
|
public PlaybackState | getPlaybackState()Get the current playback state for this session.
try {
return mSessionBinder.getPlaybackState();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getPlaybackState.", e);
return null;
}
|
public java.util.List | getQueue()Get the current play queue for this session if one is set. If you only
care about the current item {@link #getMetadata()} should be used.
try {
ParceledListSlice queue = mSessionBinder.getQueue();
if (queue != null) {
return queue.getList();
}
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getQueue.", e);
}
return null;
|
public java.lang.CharSequence | getQueueTitle()Get the queue title for this session.
try {
return mSessionBinder.getQueueTitle();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getQueueTitle", e);
}
return null;
|
public int | getRatingType()Get the rating type supported by the session. One of:
- {@link Rating#RATING_NONE}
- {@link Rating#RATING_HEART}
- {@link Rating#RATING_THUMB_UP_DOWN}
- {@link Rating#RATING_3_STARS}
- {@link Rating#RATING_4_STARS}
- {@link Rating#RATING_5_STARS}
- {@link Rating#RATING_PERCENTAGE}
try {
return mSessionBinder.getRatingType();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getRatingType.", e);
return Rating.RATING_NONE;
}
|
public android.app.PendingIntent | getSessionActivity()Get an intent for launching UI associated with this session if one
exists.
try {
return mSessionBinder.getLaunchPendingIntent();
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling getPendingIntent.", e);
}
return null;
|
ISessionController | getSessionBinder()
return mSessionBinder;
|
public MediaSession.Token | getSessionToken()Get the token for the session this is connected to.
return mToken;
|
public java.lang.String | getTag()Get the session's tag for debugging purposes.
if (mTag == null) {
try {
mTag = mSessionBinder.getTag();
} catch (RemoteException e) {
Log.d(TAG, "Dead object in getTag.", e);
}
}
return mTag;
|
public android.media.session.MediaController$TransportControls | getTransportControls()Get a {@link TransportControls} instance to send transport actions to
the associated session.
return mTransportControls;
|
private final void | postMessage(int what, java.lang.Object obj, android.os.Bundle data)
synchronized (mLock) {
for (int i = mCallbacks.size() - 1; i >= 0; i--) {
mCallbacks.get(i).post(what, obj, data);
}
}
|
public void | registerCallback(android.media.session.MediaController$Callback callback)Registers a callback to receive updates from the Session. Updates will be
posted on the caller's thread.
registerCallback(callback, null);
|
public void | registerCallback(android.media.session.MediaController$Callback callback, android.os.Handler handler)Registers a callback to receive updates from the session. Updates will be
posted on the specified handler's thread.
if (callback == null) {
throw new IllegalArgumentException("callback must not be null");
}
if (handler == null) {
handler = new Handler();
}
synchronized (mLock) {
addCallbackLocked(callback, handler);
}
|
private boolean | removeCallbackLocked(android.media.session.MediaController$Callback cb)
boolean success = false;
for (int i = mCallbacks.size() - 1; i >= 0; i--) {
MessageHandler handler = mCallbacks.get(i);
if (cb == handler.mCallback) {
mCallbacks.remove(i);
success = true;
handler.mRegistered = false;
}
}
if (mCbRegistered && mCallbacks.size() == 0) {
try {
mSessionBinder.unregisterCallbackListener(mCbStub);
} catch (RemoteException e) {
Log.e(TAG, "Dead object in removeCallbackLocked");
}
mCbRegistered = false;
}
return success;
|
public void | sendCommand(java.lang.String command, android.os.Bundle args, android.os.ResultReceiver cb)Sends a generic command to the session. It is up to the session creator
to decide what commands and parameters they will support. As such,
commands should only be sent to sessions that the controller owns.
if (TextUtils.isEmpty(command)) {
throw new IllegalArgumentException("command cannot be null or empty");
}
try {
mSessionBinder.sendCommand(command, args, cb);
} catch (RemoteException e) {
Log.d(TAG, "Dead object in sendCommand.", e);
}
|
public void | setVolumeTo(int value, int flags)Set the volume of the output this session is playing on. The command will
be ignored if it does not support
{@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}. The flags in
{@link AudioManager} may be used to affect the handling.
try {
mSessionBinder.setVolumeTo(value, flags, mContext.getPackageName());
} catch (RemoteException e) {
Log.wtf(TAG, "Error calling setVolumeTo.", e);
}
|
public void | unregisterCallback(android.media.session.MediaController$Callback callback)Unregisters the specified callback. If an update has already been posted
you may still receive it after calling this method.
if (callback == null) {
throw new IllegalArgumentException("callback must not be null");
}
synchronized (mLock) {
removeCallbackLocked(callback);
}
|