Methods Summary |
---|
public void | addOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat$OnActiveChangeListener listener)Adds a listener to be notified when the active status of this session
changes. This is primarily used by the support library and should not be
needed by apps.
if (listener == null) {
throw new IllegalArgumentException("Listener may not be null");
}
mActiveListeners.add(listener);
|
public MediaControllerCompat | 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 java.lang.Object | getMediaSession()Gets the underlying framework {@link android.media.session.MediaSession}
object.
This method is only supported on API 21+.
return mImpl.getMediaSession();
|
public java.lang.Object | getRemoteControlClient()Gets the underlying framework {@link android.media.RemoteControlClient}
object.
This method is only supported on APIs 14-20. On API 21+
{@link #getMediaSession()} should be used instead.
return mImpl.getRemoteControlClient();
|
public android.support.v4.media.session.MediaSessionCompat$Token | getSessionToken()Retrieve a token object that can be used by apps to create a
{@link MediaControllerCompat} for interacting with this session. The
owner of the session is responsible for deciding how to distribute these
tokens.
On platform versions before
{@link android.os.Build.VERSION_CODES#LOLLIPOP} this token may only be
used within your app as there is no way to guarantee other apps are using
the same version of the support library.
return mImpl.getSessionToken();
|
public boolean | isActive()Get the current active state of this session.
return mImpl.isActive();
|
public static android.support.v4.media.session.MediaSessionCompat | obtain(android.content.Context context, java.lang.Object mediaSession)Obtain a compat wrapper for an existing MediaSession.
return new MediaSessionCompat(context, new MediaSessionImplApi21(mediaSession));
|
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.
mImpl.release();
|
public void | removeOnActiveChangeListener(android.support.v4.media.session.MediaSessionCompat$OnActiveChangeListener listener)Stops the listener from being notified when the active status of this
session changes.
if (listener == null) {
throw new IllegalArgumentException("Listener may not be null");
}
mActiveListeners.remove(listener);
|
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");
}
mImpl.sendSessionEvent(event, extras);
|
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.
On platforms earlier than
{@link android.os.Build.VERSION_CODES#LOLLIPOP},
{@link #setMediaButtonReceiver(PendingIntent)} must be called before
setting this to true.
mImpl.setActive(active);
for (OnActiveChangeListener listener : mActiveListeners) {
listener.onActiveChanged();
}
|
public void | setCallback(android.support.v4.media.session.MediaSessionCompat$Callback callback)Add a callback to receive updates on for the MediaSession. This includes
media button and volume events. The caller's thread will be used to post
events.
setCallback(callback, null);
|
public void | setCallback(android.support.v4.media.session.MediaSessionCompat$Callback callback, android.os.Handler handler)Set the callback to receive updates for the MediaSession. This includes
media button and volume events. Set the callback to null to stop
receiving events.
mImpl.setCallback(callback, handler != null ? handler : new Handler());
|
public void | setExtras(android.os.Bundle extras)Set some extras that can be associated with the
{@link MediaSessionCompat}. No assumptions should be made as to how a
{@link MediaControllerCompat} will handle these extras. Keys should be
fully qualified (e.g. com.example.MY_EXTRA) to avoid conflicts.
mImpl.setExtras(extras);
|
public void | setFlags(int flags)Set any flags for the session.
mImpl.setFlags(flags);
|
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.
This method will only work on
{@link android.os.Build.VERSION_CODES#LOLLIPOP} and later. Earlier
platform versions must include the media button receiver in the
constructor.
mImpl.setMediaButtonReceiver(mbr);
|
public void | setMetadata(android.support.v4.media.MediaMetadataCompat metadata)Update the current metadata. New metadata can be created using
{@link android.media.MediaMetadata.Builder}.
mImpl.setMetadata(metadata);
|
public void | setPlaybackState(PlaybackStateCompat state)Update the current playback state.
mImpl.setPlaybackState(state);
|
public void | setPlaybackToLocal(int stream)Set the stream this session is playing on. 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 are on {@link AudioManager#STREAM_MUSIC}.
mImpl.setPlaybackToLocal(stream);
|
public void | setPlaybackToRemote(android.support.v4.media.VolumeProviderCompat volumeProvider)Configure this session to use remote volume handling. This must be called
to receive volume button events, otherwise the system will adjust the
current stream volume for this session. If {@link #setPlaybackToLocal}
was previously called that stream will stop receiving volume changes for
this session.
On platforms earlier than {@link android.os.Build.VERSION_CODES#LOLLIPOP}
this will only allow an app to handle volume commands sent directly to
the session by a {@link MediaControllerCompat}. System routing of volume
keys will not use the volume provider.
if (volumeProvider == null) {
throw new IllegalArgumentException("volumeProvider may not be null!");
}
mImpl.setPlaybackToRemote(volumeProvider);
|
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.
mImpl.setQueue(queue);
|
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.
mImpl.setQueueTitle(title);
|
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 RatingCompat#RATING_NONE}
- {@link RatingCompat#RATING_3_STARS}
- {@link RatingCompat#RATING_4_STARS}
- {@link RatingCompat#RATING_5_STARS}
- {@link RatingCompat#RATING_HEART}
- {@link RatingCompat#RATING_PERCENTAGE}
- {@link RatingCompat#RATING_THUMB_UP_DOWN}
mImpl.setRatingType(type);
|
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)}.
mImpl.setSessionActivity(pi);
|