Methods Summary |
---|
private void | dispatchAdjustVolume(int direction)
postToCallback(CallbackMessageHandler.MSG_ADJUST_VOLUME, direction);
|
private void | dispatchCustomAction(java.lang.String action, android.os.Bundle args)
postToCallback(CallbackMessageHandler.MSG_CUSTOM_ACTION, action, args);
|
private void | dispatchFastForward()
postToCallback(CallbackMessageHandler.MSG_FAST_FORWARD);
|
private void | dispatchMediaButton(android.content.Intent mediaButtonIntent)
postToCallback(CallbackMessageHandler.MSG_MEDIA_BUTTON, mediaButtonIntent);
|
private void | dispatchNext()
postToCallback(CallbackMessageHandler.MSG_NEXT);
|
private void | dispatchPause()
postToCallback(CallbackMessageHandler.MSG_PAUSE);
|
private void | dispatchPlay()
postToCallback(CallbackMessageHandler.MSG_PLAY);
|
private void | dispatchPlayFromMediaId(java.lang.String mediaId, android.os.Bundle extras)
postToCallback(CallbackMessageHandler.MSG_PLAY_MEDIA_ID, mediaId, extras);
|
private void | dispatchPlayFromSearch(java.lang.String query, android.os.Bundle extras)
postToCallback(CallbackMessageHandler.MSG_PLAY_SEARCH, query, extras);
|
private void | dispatchPrevious()
postToCallback(CallbackMessageHandler.MSG_PREVIOUS);
|
private void | dispatchRate(android.media.Rating rating)
postToCallback(CallbackMessageHandler.MSG_RATE, rating);
|
private void | dispatchRewind()
postToCallback(CallbackMessageHandler.MSG_REWIND);
|
private void | dispatchSeekTo(long pos)
postToCallback(CallbackMessageHandler.MSG_SEEK_TO, pos);
|
private void | dispatchSetVolumeTo(int volume)
postToCallback(CallbackMessageHandler.MSG_SET_VOLUME, volume);
|
private void | dispatchSkipToItem(long id)
postToCallback(CallbackMessageHandler.MSG_SKIP_TO_ITEM, id);
|
private void | dispatchStop()
postToCallback(CallbackMessageHandler.MSG_STOP);
|
public MediaController | getController()Get a controller for this session. This is a convenience method to avoid
having to cache your own controller in process.
return mController;
|
public android.media.session.MediaSession$Token | getSessionToken()Retrieve a token object that can be used by apps to create a
{@link MediaController} for interacting with this session. The owner of
the session is responsible for deciding how to distribute these tokens.
return mSessionToken;
|
public boolean | isActive()Get the current active state of this session.
return mActive;
|
public static boolean | isActiveState(int state)Return true if this is considered an active playback state.
switch (state) {
case PlaybackState.STATE_FAST_FORWARDING:
case PlaybackState.STATE_REWINDING:
case PlaybackState.STATE_SKIPPING_TO_PREVIOUS:
case PlaybackState.STATE_SKIPPING_TO_NEXT:
case PlaybackState.STATE_BUFFERING:
case PlaybackState.STATE_CONNECTING:
case PlaybackState.STATE_PLAYING:
return true;
}
return false;
|
public void | notifyRemoteVolumeChanged(android.media.VolumeProvider provider)Notify the system that the remote volume changed.
synchronized (mLock) {
if (provider == null || provider != mVolumeProvider) {
Log.w(TAG, "Received update from stale volume provider");
return;
}
}
try {
mBinder.setCurrentVolume(provider.getCurrentVolume());
} catch (RemoteException e) {
Log.e(TAG, "Error in notifyVolumeChanged", e);
}
|
private void | postCommand(java.lang.String command, android.os.Bundle args, android.os.ResultReceiver resultCb)
Command cmd = new Command(command, args, resultCb);
postToCallback(CallbackMessageHandler.MSG_COMMAND, cmd);
|
private void | postToCallback(int what)
postToCallback(what, null);
|
private void | postToCallback(int what, java.lang.Object obj)
postToCallback(what, obj, null);
|
private void | postToCallback(int what, java.lang.Object obj, android.os.Bundle extras)
synchronized (mLock) {
if (mCallback != null) {
mCallback.post(what, obj, extras);
}
}
|
public void | release()This must be called when an app has finished performing playback. If
playback is expected to start again shortly the session can be left open,
but it must be released if your activity or service is being destroyed.
try {
mBinder.destroy();
} catch (RemoteException e) {
Log.wtf(TAG, "Error releasing session: ", e);
}
|
public void | sendSessionEvent(java.lang.String event, android.os.Bundle extras)Send a proprietary event to all MediaControllers listening to this
Session. It's up to the Controller/Session owner to determine the meaning
of any events.
if (TextUtils.isEmpty(event)) {
throw new IllegalArgumentException("event cannot be null or empty");
}
try {
mBinder.sendEvent(event, extras);
} catch (RemoteException e) {
Log.wtf(TAG, "Error sending event", e);
}
|
public void | setActive(boolean active)Set if this session is currently active and ready to receive commands. If
set to false your session's controller may not be discoverable. You must
set the session to active before it can start receiving media button
events or transport commands.
if (mActive == active) {
return;
}
try {
mBinder.setActive(active);
mActive = active;
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setActive.", e);
}
|
public void | setCallback(android.media.session.MediaSession$Callback callback)Set the callback to receive updates for the MediaSession. This includes
media button events and transport controls. The caller's thread will be
used to post updates.
Set the callback to null to stop receiving updates.
setCallback(callback, null);
|
public void | setCallback(android.media.session.MediaSession$Callback callback, android.os.Handler handler)Set the callback to receive updates for the MediaSession. This includes
media button events and transport controls.
Set the callback to null to stop receiving updates.
synchronized (mLock) {
if (callback == null) {
if (mCallback != null) {
mCallback.mCallback.mSession = null;
}
mCallback = null;
return;
}
if (mCallback != null) {
// We're updating the callback, clear the session from the old
// one.
mCallback.mCallback.mSession = null;
}
if (handler == null) {
handler = new Handler();
}
callback.mSession = this;
CallbackMessageHandler msgHandler = new CallbackMessageHandler(handler.getLooper(),
callback);
mCallback = msgHandler;
}
|
public void | setExtras(android.os.Bundle extras)Set some extras that can be associated with the {@link MediaSession}. No assumptions should
be made as to how a {@link MediaController} will handle these extras.
Keys should be fully qualified (e.g. com.example.MY_EXTRA) to avoid conflicts.
try {
mBinder.setExtras(extras);
} catch (RemoteException e) {
Log.wtf("Dead object in setExtras.", e);
}
|
public void | setFlags(int flags)Set any flags for the session.
try {
mBinder.setFlags(flags);
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setFlags.", e);
}
|
public void | setMediaButtonReceiver(android.app.PendingIntent mbr)Set a pending intent for your media button receiver to allow restarting
playback after the session has been stopped. If your app is started in
this way an {@link Intent#ACTION_MEDIA_BUTTON} intent will be sent via
the pending intent.
try {
mBinder.setMediaButtonReceiver(mbr);
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setMediaButtonReceiver.", e);
}
|
public void | setMetadata(android.media.MediaMetadata metadata)Update the current metadata. New metadata can be created using
{@link android.media.MediaMetadata.Builder}.
if (metadata != null ) {
metadata = (new MediaMetadata.Builder(metadata, mMaxBitmapSize)).build();
}
try {
mBinder.setMetadata(metadata);
} catch (RemoteException e) {
Log.wtf(TAG, "Dead object in setPlaybackState.", e);
}
|
public void | setPlaybackState(PlaybackState state)Update the current playback state.
mPlaybackState = state;
try {
mBinder.setPlaybackState(state);
} catch (RemoteException e) {
Log.wtf(TAG, "Dead object in setPlaybackState.", e);
}
|
public void | setPlaybackToLocal(android.media.AudioAttributes attributes)Set the attributes for this session's audio. This will affect the
system's volume handling for this session. If
{@link #setPlaybackToRemote} was previously called it will stop receiving
volume commands and the system will begin sending volume changes to the
appropriate stream.
By default sessions use attributes for media.
if (attributes == null) {
throw new IllegalArgumentException("Attributes cannot be null for local playback.");
}
try {
mBinder.setPlaybackToLocal(attributes);
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setPlaybackToLocal.", e);
}
|
public void | setPlaybackToRemote(android.media.VolumeProvider volumeProvider)Configure this session to use remote volume handling. This must be called
to receive volume button events, otherwise the system will adjust the
appropriate stream volume for this session. If
{@link #setPlaybackToLocal} was previously called the system will stop
handling volume changes for this session and pass them to the volume
provider instead.
if (volumeProvider == null) {
throw new IllegalArgumentException("volumeProvider may not be null!");
}
synchronized (mLock) {
mVolumeProvider = volumeProvider;
}
volumeProvider.setCallback(new VolumeProvider.Callback() {
@Override
public void onVolumeChanged(VolumeProvider volumeProvider) {
notifyRemoteVolumeChanged(volumeProvider);
}
});
try {
mBinder.setPlaybackToRemote(volumeProvider.getVolumeControl(),
volumeProvider.getMaxVolume());
mBinder.setCurrentVolume(volumeProvider.getCurrentVolume());
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setPlaybackToRemote.", e);
}
|
public void | setQueue(java.util.List queue)Update the list of items in the play queue. It is an ordered list and
should contain the current item, and previous or upcoming items if they
exist. Specify null if there is no current play queue.
The queue should be of reasonable size. If the play queue is unbounded
within your app, it is better to send a reasonable amount in a sliding
window instead.
try {
mBinder.setQueue(queue == null ? null : new ParceledListSlice<QueueItem>(queue));
} catch (RemoteException e) {
Log.wtf("Dead object in setQueue.", e);
}
|
public void | setQueueTitle(java.lang.CharSequence title)Set the title of the play queue. The UI should display this title along
with the play queue itself.
e.g. "Play Queue", "Now Playing", or an album name.
try {
mBinder.setQueueTitle(title);
} catch (RemoteException e) {
Log.wtf("Dead object in setQueueTitle.", e);
}
|
public void | setRatingType(int type)Set the style of rating used by this session. Apps trying to set the
rating should use this style. Must be one of the following:
- {@link Rating#RATING_NONE}
- {@link Rating#RATING_3_STARS}
- {@link Rating#RATING_4_STARS}
- {@link Rating#RATING_5_STARS}
- {@link Rating#RATING_HEART}
- {@link Rating#RATING_PERCENTAGE}
- {@link Rating#RATING_THUMB_UP_DOWN}
try {
mBinder.setRatingType(type);
} catch (RemoteException e) {
Log.e(TAG, "Error in setRatingType.", e);
}
|
public void | setSessionActivity(android.app.PendingIntent pi)Set an intent for launching UI for this Session. This can be used as a
quick link to an ongoing media screen. The intent should be for an
activity that may be started using {@link Activity#startActivity(Intent)}.
try {
mBinder.setLaunchPendingIntent(pi);
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setLaunchPendingIntent.", e);
}
|