Loading media/java/android/media/MediaMetadata.java +4 −4 Original line number Diff line number Diff line Loading @@ -260,7 +260,7 @@ public final class MediaMetadata implements Parcelable { rating = mBundle.getParcelable(key); } catch (Exception e) { // ignore, value was not a bitmap Log.d(TAG, "Failed to retrieve a key as Rating.", e); Log.w(TAG, "Failed to retrieve a key as Rating.", e); } return rating; } Loading @@ -278,7 +278,7 @@ public final class MediaMetadata implements Parcelable { bmp = mBundle.getParcelable(key); } catch (Exception e) { // ignore, value was not a bitmap Log.d(TAG, "Failed to retrieve a key as Bitmap.", e); Log.w(TAG, "Failed to retrieve a key as Bitmap.", e); } return bmp; } Loading Loading @@ -323,8 +323,8 @@ public final class MediaMetadata implements Parcelable { return EDITOR_KEY_MAPPING.get(editorKey, null); } public static final Parcelable.Creator<MediaMetadata> CREATOR = new Parcelable.Creator<MediaMetadata>() { public static final Parcelable.Creator<MediaMetadata> CREATOR = new Parcelable.Creator<MediaMetadata>() { @Override public MediaMetadata createFromParcel(Parcel in) { return new MediaMetadata(in); Loading media/java/android/media/Rating.java +5 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.util.Log; */ public final class Rating implements Parcelable { private final static String TAG = "Rating"; /** * Indicates a rating style is not supported. A Rating will never have this * type, but can be used by other classes to indicate they do not support Loading Loading @@ -79,10 +80,6 @@ public final class Rating implements Parcelable { mRatingValue = rating; } /** * @hide */ @Override public String toString() { return "Rating:style=" + mRatingStyle + " rating=" Loading @@ -107,9 +104,12 @@ public final class Rating implements Parcelable { * @param p Parcel object to read the Rating from * @return a new Rating created from the data in the parcel */ @Override public Rating createFromParcel(Parcel p) { return new Rating(p.readInt(), p.readFloat()); } @Override public Rating[] newArray(int size) { return new Rating[size]; } Loading media/java/android/media/VolumeProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.media; import android.media.session.MediaSession; import android.os.RemoteException; import android.util.Log; /** * Handles requests to adjust or set the volume on a session. This is also used Loading @@ -26,8 +24,6 @@ import android.util.Log; * {@link MediaSession#setPlaybackToRemote}. */ public abstract class VolumeProvider { private static final String TAG = "VolumeProvider"; /** * The volume is fixed and can not be modified. Requests to change volume * should be ignored. Loading @@ -50,8 +46,7 @@ public abstract class VolumeProvider { private final int mControlType; private final int mMaxVolume; private MediaSession mSession; private Callback mCallback; /** * Create a new volume provider for handling volume events. You must specify Loading Loading @@ -92,10 +87,12 @@ public abstract class VolumeProvider { } /** * Notify the system that the remote playback's volume has been changed. * Notify the system that the volume has been changed. */ public final void notifyVolumeChanged() { mSession.notifyRemoteVolumeChanged(this); if (mCallback != null) { mCallback.onVolumeChanged(this); } } /** Loading @@ -116,9 +113,18 @@ public abstract class VolumeProvider { } /** * Sets a callback to receive volume changes. * @hide */ public void setCallback(Callback callback) { mCallback = callback; } /** * Listens for changes to the volume. * @hide */ public void setSession(MediaSession session) { mSession = session; public static abstract class Callback { public abstract void onVolumeChanged(VolumeProvider volumeProvider); } } No newline at end of file media/java/android/media/session/MediaController.java +38 −37 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.media.session; import android.annotation.NonNull; import android.annotation.Nullable; import android.media.MediaMetadata; import android.media.Rating; import android.media.VolumeProvider; Loading Loading @@ -44,7 +46,7 @@ import java.util.ArrayList; * MediaController objects are thread-safe. */ public final class MediaController { private static final String TAG = "SessionController"; private static final String TAG = "MediaController"; private static final int MSG_EVENT = 1; private static final int MSG_UPDATE_PLAYBACK_STATE = 2; Loading Loading @@ -75,14 +77,14 @@ public final class MediaController { } /** * Get a new MediaController for a MediaSessionToken. If successful the * controller returned will be connected to the session that generated the * token. * Get a new media controller from a session token which may have * been obtained from another process. If successful the controller returned * will be connected to the session that generated the token. * * @param token The session token to use * @return A controller for the session or null * @param token The session token to control. * @return A controller for the session or null if inaccessible. */ public static MediaController fromToken(MediaSessionToken token) { public static MediaController fromToken(@NonNull MediaSessionToken token) { return fromBinder(token.getBinder()); } Loading @@ -91,7 +93,7 @@ public final class MediaController { * * @return A controls instance */ public TransportControls getTransportControls() { public @NonNull TransportControls getTransportControls() { return mTransportController; } Loading @@ -102,7 +104,7 @@ public final class MediaController { * @param keyEvent The media button event to dispatch. * @return true if the event was sent to the session, false otherwise. */ public boolean dispatchMediaButtonEvent(KeyEvent keyEvent) { public boolean dispatchMediaButtonEvent(@NonNull KeyEvent keyEvent) { if (keyEvent == null) { throw new IllegalArgumentException("KeyEvent may not be null"); } Loading @@ -122,7 +124,7 @@ public final class MediaController { * * @return The current PlaybackState or null */ public PlaybackState getPlaybackState() { public @Nullable PlaybackState getPlaybackState() { try { return mSessionBinder.getPlaybackState(); } catch (RemoteException e) { Loading @@ -136,7 +138,7 @@ public final class MediaController { * * @return The current MediaMetadata or null. */ public MediaMetadata getMetadata() { public @Nullable MediaMetadata getMetadata() { try { return mSessionBinder.getMetadata(); } catch (RemoteException e) { Loading Loading @@ -188,7 +190,7 @@ public final class MediaController { * * @return The current volume info or null. */ public VolumeInfo getVolumeInfo() { public @Nullable VolumeInfo getVolumeInfo() { try { ParcelableVolumeInfo result = mSessionBinder.getVolumeAttributes(); return new VolumeInfo(result.volumeType, result.audioStream, result.controlType, Loading @@ -204,26 +206,29 @@ public final class MediaController { * Adds a callback to receive updates from the Session. Updates will be * posted on the caller's thread. * * @param cb The callback object, must not be null * @param callback The callback object, must not be null. */ public void addCallback(Callback cb) { addCallback(cb, null); public void addCallback(@NonNull Callback callback) { addCallback(callback, null); } /** * Adds a callback to receive updates from the session. Updates will be * posted on the specified handler's thread. * * @param cb Cannot be null. * @param callback The callback object, must not be null. * @param handler The handler to post updates on. If null the callers thread * will be used * will be used. */ public void addCallback(Callback cb, Handler handler) { public void addCallback(@NonNull Callback callback, @Nullable Handler handler) { if (callback == null) { throw new IllegalArgumentException("callback must not be null"); } if (handler == null) { handler = new Handler(); } synchronized (mLock) { addCallbackLocked(cb, handler); addCallbackLocked(callback, handler); } } Loading @@ -231,11 +236,14 @@ public final class MediaController { * Stop receiving updates on the specified callback. If an update has * already been posted you may still receive it after calling this method. * * @param cb The callback to remove * @param callback The callback to remove. */ public void removeCallback(Callback cb) { public void removeCallback(@NonNull Callback callback) { if (callback == null) { throw new IllegalArgumentException("callback must not be null"); } synchronized (mLock) { removeCallbackLocked(cb); removeCallbackLocked(callback); } } Loading @@ -248,7 +256,8 @@ public final class MediaController { * @param params Any parameters to include with the command * @param cb The callback to receive the result on */ public void sendControlCommand(String command, Bundle params, ResultReceiver cb) { public void sendControlCommand(@NonNull String command, @Nullable Bundle params, @Nullable ResultReceiver cb) { if (TextUtils.isEmpty(command)) { throw new IllegalArgumentException("command cannot be null or empty"); } Loading Loading @@ -298,12 +307,6 @@ public final class MediaController { } private void addCallbackLocked(Callback cb, Handler handler) { if (cb == null) { throw new IllegalArgumentException("Callback cannot be null"); } if (handler == null) { throw new IllegalArgumentException("Handler cannot be null"); } if (getHandlerForCallbackLocked(cb) != null) { Log.w(TAG, "Callback is already added, ignoring"); return; Loading @@ -322,9 +325,6 @@ public final class MediaController { } private boolean removeCallbackLocked(Callback cb) { if (cb == null) { throw new IllegalArgumentException("Callback cannot be null"); } boolean success = false; for (int i = mCallbacks.size() - 1; i >= 0; i--) { MessageHandler handler = mCallbacks.get(i); Loading Loading @@ -375,9 +375,10 @@ public final class MediaController { * specified interface. Controllers should only handle these for * sessions they own. * * @param event * @param event The event from the session. * @param extras Optional parameters for the event, may be null. */ public void onSessionEvent(String event, Bundle extras) { public void onSessionEvent(@NonNull String event, @Nullable Bundle extras) { } /** Loading @@ -394,16 +395,16 @@ public final class MediaController { * * @param state The new playback state of the session */ public void onPlaybackStateChanged(PlaybackState state) { public void onPlaybackStateChanged(@NonNull PlaybackState state) { } /** * Override to handle changes to the current metadata. * * @param metadata The current metadata for the session or null if none. * @see MediaMetadata * @param metadata The current metadata for the session or null */ public void onMetadataChanged(MediaMetadata metadata) { public void onMetadataChanged(@Nullable MediaMetadata metadata) { } } Loading media/java/android/media/session/MediaSession.java +31 −26 Original line number Diff line number Diff line Loading @@ -51,10 +51,9 @@ import java.util.List; * for all playback, though multiple sessions can be created to provide finer * grain controls of media. * <p> * A MediaSession is created by calling * {@link MediaSessionManager#createSession(String)}. Once a session is created * the owner of the session may use {@link #getSessionToken()} to allow apps to * create a {@link MediaController} to interact with this session. * Once a session is created the owner of the session may pass its * {@link #getSessionToken() session token} to other processes to allow them to * create a {@link MediaController} to interact with the session. * <p> * To receive commands, media keys, and other events a {@link Callback} must be * set with {@link #addCallback(Callback)}. To receive transport control Loading @@ -64,10 +63,10 @@ import java.util.List; * When an app is finished performing playback it must call {@link #release()} * to clean up the session and notify any controllers. * <p> * MediaSession objects are thread safe * MediaSession objects are thread safe. */ public final class MediaSession { private static final String TAG = "Session"; private static final String TAG = "MediaSession"; /** * Set this flag on the session to indicate that it can handle media button Loading @@ -77,9 +76,8 @@ public final class MediaSession { /** * Set this flag on the session to indicate that it handles transport * control commands through a {@link TransportControlsCallback}. The * callback can be retrieved by calling * {@link #addTransportControlsCallback}. * control commands through a {@link TransportControlsCallback}. * The callback can be retrieved by calling {@link #addTransportControlsCallback}. */ public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 1 << 1; Loading Loading @@ -153,7 +151,7 @@ public final class MediaSession { private Route mRoute; private VolumeProvider mVolumeProvider; private boolean mActive = false;; private boolean mActive = false; /** * @hide Loading @@ -177,7 +175,7 @@ public final class MediaSession { * * @param callback The callback object */ public void addCallback(Callback callback) { public void addCallback(@NonNull Callback callback) { addCallback(callback, null); } Loading @@ -188,7 +186,7 @@ public final class MediaSession { * @param callback The callback to receive updates on. * @param handler The handler that events should be posted on. */ public void addCallback(Callback callback, Handler handler) { public void addCallback(@NonNull Callback callback, @Nullable Handler handler) { if (callback == null) { throw new IllegalArgumentException("Callback cannot be null"); } Loading @@ -211,7 +209,7 @@ public final class MediaSession { * * @param callback The callback to remove. */ public void removeCallback(Callback callback) { public void removeCallback(@NonNull Callback callback) { synchronized (mLock) { removeCallbackLocked(callback); } Loading @@ -223,7 +221,7 @@ public final class MediaSession { * * @param pi The intent to launch to show UI for this Session. */ public void setLaunchPendingIntent(PendingIntent pi) { public void setLaunchPendingIntent(@Nullable PendingIntent pi) { // TODO } Loading @@ -234,7 +232,7 @@ public final class MediaSession { * @param mbr The receiver component to send the media button event to. * @hide */ public void setMediaButtonReceiver(ComponentName mbr) { public void setMediaButtonReceiver(@Nullable ComponentName mbr) { try { mBinder.setMediaButtonReceiver(mbr); } catch (RemoteException e) { Loading Loading @@ -283,12 +281,17 @@ public final class MediaSession { * @param volumeProvider The provider that will handle volume changes. May * not be null. */ public void setPlaybackToRemote(VolumeProvider volumeProvider) { public void setPlaybackToRemote(@NonNull VolumeProvider volumeProvider) { if (volumeProvider == null) { throw new IllegalArgumentException("volumeProvider may not be null!"); } mVolumeProvider = volumeProvider; volumeProvider.setSession(this); volumeProvider.setCallback(new VolumeProvider.Callback() { @Override public void onVolumeChanged(VolumeProvider volumeProvider) { notifyRemoteVolumeChanged(volumeProvider); } }); try { mBinder.configureVolumeHandling(VOLUME_TYPE_REMOTE, volumeProvider.getVolumeControl(), Loading Loading @@ -335,7 +338,7 @@ public final class MediaSession { * @param event The name of the event to send * @param extras Any extras included with the event */ public void sendSessionEvent(String event, Bundle extras) { public void sendSessionEvent(@NonNull String event, @Nullable Bundle extras) { if (TextUtils.isEmpty(event)) { throw new IllegalArgumentException("event cannot be null or empty"); } Loading Loading @@ -367,7 +370,7 @@ public final class MediaSession { * @return A token that can be used to create a MediaController for this * session */ public MediaSessionToken getSessionToken() { public @NonNull MediaSessionToken getSessionToken() { return mSessionToken; } Loading Loading @@ -512,7 +515,7 @@ public final class MediaSession { * * @param state The current state of playback */ public void setPlaybackState(PlaybackState state) { public void setPlaybackState(@Nullable PlaybackState state) { try { mBinder.setPlaybackState(state); } catch (RemoteException e) { Loading @@ -526,7 +529,7 @@ public final class MediaSession { * * @param metadata The new metadata */ public void setMetadata(MediaMetadata metadata) { public void setMetadata(@Nullable MediaMetadata metadata) { try { mBinder.setMetadata(metadata); } catch (RemoteException e) { Loading Loading @@ -714,7 +717,7 @@ public final class MediaSession { * @param mediaButtonIntent an intent containing the KeyEvent as an * extra */ public void onMediaButtonEvent(Intent mediaButtonIntent) { public void onMediaButtonEvent(@NonNull Intent mediaButtonIntent) { } /** Loading @@ -722,10 +725,12 @@ public final class MediaSession { * The owner of the session may handle custom commands but is not * required to. * * @param command * @param extras optional * @param command The command name. * @param extras Optional parameters for the command, may be null. * @param cb A result receiver to which a result may be sent by the command, may be null. */ public void onControlCommand(String command, Bundle extras, ResultReceiver cb) { public void onControlCommand(@NonNull String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) { } /** Loading Loading @@ -831,7 +836,7 @@ public final class MediaSession { * * @param rating */ public void onSetRating(Rating rating) { public void onSetRating(@NonNull Rating rating) { } /** Loading Loading
media/java/android/media/MediaMetadata.java +4 −4 Original line number Diff line number Diff line Loading @@ -260,7 +260,7 @@ public final class MediaMetadata implements Parcelable { rating = mBundle.getParcelable(key); } catch (Exception e) { // ignore, value was not a bitmap Log.d(TAG, "Failed to retrieve a key as Rating.", e); Log.w(TAG, "Failed to retrieve a key as Rating.", e); } return rating; } Loading @@ -278,7 +278,7 @@ public final class MediaMetadata implements Parcelable { bmp = mBundle.getParcelable(key); } catch (Exception e) { // ignore, value was not a bitmap Log.d(TAG, "Failed to retrieve a key as Bitmap.", e); Log.w(TAG, "Failed to retrieve a key as Bitmap.", e); } return bmp; } Loading Loading @@ -323,8 +323,8 @@ public final class MediaMetadata implements Parcelable { return EDITOR_KEY_MAPPING.get(editorKey, null); } public static final Parcelable.Creator<MediaMetadata> CREATOR = new Parcelable.Creator<MediaMetadata>() { public static final Parcelable.Creator<MediaMetadata> CREATOR = new Parcelable.Creator<MediaMetadata>() { @Override public MediaMetadata createFromParcel(Parcel in) { return new MediaMetadata(in); Loading
media/java/android/media/Rating.java +5 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.util.Log; */ public final class Rating implements Parcelable { private final static String TAG = "Rating"; /** * Indicates a rating style is not supported. A Rating will never have this * type, but can be used by other classes to indicate they do not support Loading Loading @@ -79,10 +80,6 @@ public final class Rating implements Parcelable { mRatingValue = rating; } /** * @hide */ @Override public String toString() { return "Rating:style=" + mRatingStyle + " rating=" Loading @@ -107,9 +104,12 @@ public final class Rating implements Parcelable { * @param p Parcel object to read the Rating from * @return a new Rating created from the data in the parcel */ @Override public Rating createFromParcel(Parcel p) { return new Rating(p.readInt(), p.readFloat()); } @Override public Rating[] newArray(int size) { return new Rating[size]; } Loading
media/java/android/media/VolumeProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.media; import android.media.session.MediaSession; import android.os.RemoteException; import android.util.Log; /** * Handles requests to adjust or set the volume on a session. This is also used Loading @@ -26,8 +24,6 @@ import android.util.Log; * {@link MediaSession#setPlaybackToRemote}. */ public abstract class VolumeProvider { private static final String TAG = "VolumeProvider"; /** * The volume is fixed and can not be modified. Requests to change volume * should be ignored. Loading @@ -50,8 +46,7 @@ public abstract class VolumeProvider { private final int mControlType; private final int mMaxVolume; private MediaSession mSession; private Callback mCallback; /** * Create a new volume provider for handling volume events. You must specify Loading Loading @@ -92,10 +87,12 @@ public abstract class VolumeProvider { } /** * Notify the system that the remote playback's volume has been changed. * Notify the system that the volume has been changed. */ public final void notifyVolumeChanged() { mSession.notifyRemoteVolumeChanged(this); if (mCallback != null) { mCallback.onVolumeChanged(this); } } /** Loading @@ -116,9 +113,18 @@ public abstract class VolumeProvider { } /** * Sets a callback to receive volume changes. * @hide */ public void setCallback(Callback callback) { mCallback = callback; } /** * Listens for changes to the volume. * @hide */ public void setSession(MediaSession session) { mSession = session; public static abstract class Callback { public abstract void onVolumeChanged(VolumeProvider volumeProvider); } } No newline at end of file
media/java/android/media/session/MediaController.java +38 −37 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.media.session; import android.annotation.NonNull; import android.annotation.Nullable; import android.media.MediaMetadata; import android.media.Rating; import android.media.VolumeProvider; Loading Loading @@ -44,7 +46,7 @@ import java.util.ArrayList; * MediaController objects are thread-safe. */ public final class MediaController { private static final String TAG = "SessionController"; private static final String TAG = "MediaController"; private static final int MSG_EVENT = 1; private static final int MSG_UPDATE_PLAYBACK_STATE = 2; Loading Loading @@ -75,14 +77,14 @@ public final class MediaController { } /** * Get a new MediaController for a MediaSessionToken. If successful the * controller returned will be connected to the session that generated the * token. * Get a new media controller from a session token which may have * been obtained from another process. If successful the controller returned * will be connected to the session that generated the token. * * @param token The session token to use * @return A controller for the session or null * @param token The session token to control. * @return A controller for the session or null if inaccessible. */ public static MediaController fromToken(MediaSessionToken token) { public static MediaController fromToken(@NonNull MediaSessionToken token) { return fromBinder(token.getBinder()); } Loading @@ -91,7 +93,7 @@ public final class MediaController { * * @return A controls instance */ public TransportControls getTransportControls() { public @NonNull TransportControls getTransportControls() { return mTransportController; } Loading @@ -102,7 +104,7 @@ public final class MediaController { * @param keyEvent The media button event to dispatch. * @return true if the event was sent to the session, false otherwise. */ public boolean dispatchMediaButtonEvent(KeyEvent keyEvent) { public boolean dispatchMediaButtonEvent(@NonNull KeyEvent keyEvent) { if (keyEvent == null) { throw new IllegalArgumentException("KeyEvent may not be null"); } Loading @@ -122,7 +124,7 @@ public final class MediaController { * * @return The current PlaybackState or null */ public PlaybackState getPlaybackState() { public @Nullable PlaybackState getPlaybackState() { try { return mSessionBinder.getPlaybackState(); } catch (RemoteException e) { Loading @@ -136,7 +138,7 @@ public final class MediaController { * * @return The current MediaMetadata or null. */ public MediaMetadata getMetadata() { public @Nullable MediaMetadata getMetadata() { try { return mSessionBinder.getMetadata(); } catch (RemoteException e) { Loading Loading @@ -188,7 +190,7 @@ public final class MediaController { * * @return The current volume info or null. */ public VolumeInfo getVolumeInfo() { public @Nullable VolumeInfo getVolumeInfo() { try { ParcelableVolumeInfo result = mSessionBinder.getVolumeAttributes(); return new VolumeInfo(result.volumeType, result.audioStream, result.controlType, Loading @@ -204,26 +206,29 @@ public final class MediaController { * Adds a callback to receive updates from the Session. Updates will be * posted on the caller's thread. * * @param cb The callback object, must not be null * @param callback The callback object, must not be null. */ public void addCallback(Callback cb) { addCallback(cb, null); public void addCallback(@NonNull Callback callback) { addCallback(callback, null); } /** * Adds a callback to receive updates from the session. Updates will be * posted on the specified handler's thread. * * @param cb Cannot be null. * @param callback The callback object, must not be null. * @param handler The handler to post updates on. If null the callers thread * will be used * will be used. */ public void addCallback(Callback cb, Handler handler) { public void addCallback(@NonNull Callback callback, @Nullable Handler handler) { if (callback == null) { throw new IllegalArgumentException("callback must not be null"); } if (handler == null) { handler = new Handler(); } synchronized (mLock) { addCallbackLocked(cb, handler); addCallbackLocked(callback, handler); } } Loading @@ -231,11 +236,14 @@ public final class MediaController { * Stop receiving updates on the specified callback. If an update has * already been posted you may still receive it after calling this method. * * @param cb The callback to remove * @param callback The callback to remove. */ public void removeCallback(Callback cb) { public void removeCallback(@NonNull Callback callback) { if (callback == null) { throw new IllegalArgumentException("callback must not be null"); } synchronized (mLock) { removeCallbackLocked(cb); removeCallbackLocked(callback); } } Loading @@ -248,7 +256,8 @@ public final class MediaController { * @param params Any parameters to include with the command * @param cb The callback to receive the result on */ public void sendControlCommand(String command, Bundle params, ResultReceiver cb) { public void sendControlCommand(@NonNull String command, @Nullable Bundle params, @Nullable ResultReceiver cb) { if (TextUtils.isEmpty(command)) { throw new IllegalArgumentException("command cannot be null or empty"); } Loading Loading @@ -298,12 +307,6 @@ public final class MediaController { } private void addCallbackLocked(Callback cb, Handler handler) { if (cb == null) { throw new IllegalArgumentException("Callback cannot be null"); } if (handler == null) { throw new IllegalArgumentException("Handler cannot be null"); } if (getHandlerForCallbackLocked(cb) != null) { Log.w(TAG, "Callback is already added, ignoring"); return; Loading @@ -322,9 +325,6 @@ public final class MediaController { } private boolean removeCallbackLocked(Callback cb) { if (cb == null) { throw new IllegalArgumentException("Callback cannot be null"); } boolean success = false; for (int i = mCallbacks.size() - 1; i >= 0; i--) { MessageHandler handler = mCallbacks.get(i); Loading Loading @@ -375,9 +375,10 @@ public final class MediaController { * specified interface. Controllers should only handle these for * sessions they own. * * @param event * @param event The event from the session. * @param extras Optional parameters for the event, may be null. */ public void onSessionEvent(String event, Bundle extras) { public void onSessionEvent(@NonNull String event, @Nullable Bundle extras) { } /** Loading @@ -394,16 +395,16 @@ public final class MediaController { * * @param state The new playback state of the session */ public void onPlaybackStateChanged(PlaybackState state) { public void onPlaybackStateChanged(@NonNull PlaybackState state) { } /** * Override to handle changes to the current metadata. * * @param metadata The current metadata for the session or null if none. * @see MediaMetadata * @param metadata The current metadata for the session or null */ public void onMetadataChanged(MediaMetadata metadata) { public void onMetadataChanged(@Nullable MediaMetadata metadata) { } } Loading
media/java/android/media/session/MediaSession.java +31 −26 Original line number Diff line number Diff line Loading @@ -51,10 +51,9 @@ import java.util.List; * for all playback, though multiple sessions can be created to provide finer * grain controls of media. * <p> * A MediaSession is created by calling * {@link MediaSessionManager#createSession(String)}. Once a session is created * the owner of the session may use {@link #getSessionToken()} to allow apps to * create a {@link MediaController} to interact with this session. * Once a session is created the owner of the session may pass its * {@link #getSessionToken() session token} to other processes to allow them to * create a {@link MediaController} to interact with the session. * <p> * To receive commands, media keys, and other events a {@link Callback} must be * set with {@link #addCallback(Callback)}. To receive transport control Loading @@ -64,10 +63,10 @@ import java.util.List; * When an app is finished performing playback it must call {@link #release()} * to clean up the session and notify any controllers. * <p> * MediaSession objects are thread safe * MediaSession objects are thread safe. */ public final class MediaSession { private static final String TAG = "Session"; private static final String TAG = "MediaSession"; /** * Set this flag on the session to indicate that it can handle media button Loading @@ -77,9 +76,8 @@ public final class MediaSession { /** * Set this flag on the session to indicate that it handles transport * control commands through a {@link TransportControlsCallback}. The * callback can be retrieved by calling * {@link #addTransportControlsCallback}. * control commands through a {@link TransportControlsCallback}. * The callback can be retrieved by calling {@link #addTransportControlsCallback}. */ public static final int FLAG_HANDLES_TRANSPORT_CONTROLS = 1 << 1; Loading Loading @@ -153,7 +151,7 @@ public final class MediaSession { private Route mRoute; private VolumeProvider mVolumeProvider; private boolean mActive = false;; private boolean mActive = false; /** * @hide Loading @@ -177,7 +175,7 @@ public final class MediaSession { * * @param callback The callback object */ public void addCallback(Callback callback) { public void addCallback(@NonNull Callback callback) { addCallback(callback, null); } Loading @@ -188,7 +186,7 @@ public final class MediaSession { * @param callback The callback to receive updates on. * @param handler The handler that events should be posted on. */ public void addCallback(Callback callback, Handler handler) { public void addCallback(@NonNull Callback callback, @Nullable Handler handler) { if (callback == null) { throw new IllegalArgumentException("Callback cannot be null"); } Loading @@ -211,7 +209,7 @@ public final class MediaSession { * * @param callback The callback to remove. */ public void removeCallback(Callback callback) { public void removeCallback(@NonNull Callback callback) { synchronized (mLock) { removeCallbackLocked(callback); } Loading @@ -223,7 +221,7 @@ public final class MediaSession { * * @param pi The intent to launch to show UI for this Session. */ public void setLaunchPendingIntent(PendingIntent pi) { public void setLaunchPendingIntent(@Nullable PendingIntent pi) { // TODO } Loading @@ -234,7 +232,7 @@ public final class MediaSession { * @param mbr The receiver component to send the media button event to. * @hide */ public void setMediaButtonReceiver(ComponentName mbr) { public void setMediaButtonReceiver(@Nullable ComponentName mbr) { try { mBinder.setMediaButtonReceiver(mbr); } catch (RemoteException e) { Loading Loading @@ -283,12 +281,17 @@ public final class MediaSession { * @param volumeProvider The provider that will handle volume changes. May * not be null. */ public void setPlaybackToRemote(VolumeProvider volumeProvider) { public void setPlaybackToRemote(@NonNull VolumeProvider volumeProvider) { if (volumeProvider == null) { throw new IllegalArgumentException("volumeProvider may not be null!"); } mVolumeProvider = volumeProvider; volumeProvider.setSession(this); volumeProvider.setCallback(new VolumeProvider.Callback() { @Override public void onVolumeChanged(VolumeProvider volumeProvider) { notifyRemoteVolumeChanged(volumeProvider); } }); try { mBinder.configureVolumeHandling(VOLUME_TYPE_REMOTE, volumeProvider.getVolumeControl(), Loading Loading @@ -335,7 +338,7 @@ public final class MediaSession { * @param event The name of the event to send * @param extras Any extras included with the event */ public void sendSessionEvent(String event, Bundle extras) { public void sendSessionEvent(@NonNull String event, @Nullable Bundle extras) { if (TextUtils.isEmpty(event)) { throw new IllegalArgumentException("event cannot be null or empty"); } Loading Loading @@ -367,7 +370,7 @@ public final class MediaSession { * @return A token that can be used to create a MediaController for this * session */ public MediaSessionToken getSessionToken() { public @NonNull MediaSessionToken getSessionToken() { return mSessionToken; } Loading Loading @@ -512,7 +515,7 @@ public final class MediaSession { * * @param state The current state of playback */ public void setPlaybackState(PlaybackState state) { public void setPlaybackState(@Nullable PlaybackState state) { try { mBinder.setPlaybackState(state); } catch (RemoteException e) { Loading @@ -526,7 +529,7 @@ public final class MediaSession { * * @param metadata The new metadata */ public void setMetadata(MediaMetadata metadata) { public void setMetadata(@Nullable MediaMetadata metadata) { try { mBinder.setMetadata(metadata); } catch (RemoteException e) { Loading Loading @@ -714,7 +717,7 @@ public final class MediaSession { * @param mediaButtonIntent an intent containing the KeyEvent as an * extra */ public void onMediaButtonEvent(Intent mediaButtonIntent) { public void onMediaButtonEvent(@NonNull Intent mediaButtonIntent) { } /** Loading @@ -722,10 +725,12 @@ public final class MediaSession { * The owner of the session may handle custom commands but is not * required to. * * @param command * @param extras optional * @param command The command name. * @param extras Optional parameters for the command, may be null. * @param cb A result receiver to which a result may be sent by the command, may be null. */ public void onControlCommand(String command, Bundle extras, ResultReceiver cb) { public void onControlCommand(@NonNull String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) { } /** Loading Loading @@ -831,7 +836,7 @@ public final class MediaSession { * * @param rating */ public void onSetRating(Rating rating) { public void onSetRating(@NonNull Rating rating) { } /** Loading