diff options
Diffstat (limited to 'media/java/android/media/session/MediaController.java')
-rw-r--r-- | media/java/android/media/session/MediaController.java | 121 |
1 files changed, 110 insertions, 11 deletions
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java index 5ca7daa..84dad25 100644 --- a/media/java/android/media/session/MediaController.java +++ b/media/java/android/media/session/MediaController.java @@ -18,6 +18,7 @@ package android.media.session; import android.media.MediaMetadata; import android.media.Rating; +import android.media.VolumeProvider; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -70,14 +71,7 @@ public final class MediaController { * @hide */ public static MediaController fromBinder(ISessionController sessionBinder) { - MediaController controller = new MediaController(sessionBinder); - try { - controller.mSessionBinder.registerCallbackListener(controller.mCbStub); - } catch (RemoteException e) { - Log.wtf(TAG, "MediaController created with expired token", e); - controller = null; - } - return controller; + return new MediaController(sessionBinder); } /** @@ -190,6 +184,23 @@ public final class MediaController { } /** + * Get the current volume info for this session. + * + * @return The current volume info or null. + */ + public VolumeInfo getVolumeInfo() { + try { + ParcelableVolumeInfo result = mSessionBinder.getVolumeAttributes(); + return new VolumeInfo(result.volumeType, result.audioStream, result.controlType, + result.maxVolume, result.currentVolume); + + } catch (RemoteException e) { + Log.wtf(TAG, "Error calling getVolumeInfo.", e); + } + return null; + } + + /** * Adds a callback to receive updates from the Session. Updates will be * posted on the caller's thread. * @@ -305,7 +316,7 @@ public final class MediaController { mSessionBinder.registerCallbackListener(mCbStub); mCbRegistered = true; } catch (RemoteException e) { - Log.d(TAG, "Dead object in registerCallback", e); + Log.e(TAG, "Dead object in registerCallback", e); } } } @@ -314,14 +325,23 @@ public final class MediaController { 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); if (cb == handler.mCallback) { mCallbacks.remove(i); - return true; + success = true; } } - return false; + if (mCbRegistered && mCallbacks.size() == 0) { + try { + mSessionBinder.unregisterCallbackListener(mCbStub); + } catch (RemoteException e) { + Log.e(TAG, "Dead object in removeCallbackLocked"); + } + mCbRegistered = false; + } + return success; } private MessageHandler getHandlerForCallbackLocked(Callback cb) { @@ -507,6 +527,85 @@ public final class MediaController { } } + /** + * Holds information about the way volume is handled for this session. + */ + public static final class VolumeInfo { + private final int mVolumeType; + private final int mAudioStream; + private final int mVolumeControl; + private final int mMaxVolume; + private final int mCurrentVolume; + + /** + * @hide + */ + public VolumeInfo(int type, int stream, int control, int max, int current) { + mVolumeType = type; + mAudioStream = stream; + mVolumeControl = control; + mMaxVolume = max; + mCurrentVolume = current; + } + + /** + * Get the type of volume handling, either local or remote. One of: + * <ul> + * <li>{@link MediaSession#VOLUME_TYPE_LOCAL}</li> + * <li>{@link MediaSession#VOLUME_TYPE_REMOTE}</li> + * </ul> + * + * @return The type of volume handling this session is using. + */ + public int getVolumeType() { + return mVolumeType; + } + + /** + * Get the stream this is currently controlling volume on. When the volume + * type is {@link MediaSession#VOLUME_TYPE_REMOTE} this value does not + * have meaning and should be ignored. + * + * @return The stream this session is playing on. + */ + public int getAudioStream() { + return mAudioStream; + } + + /** + * Get the type of volume control that can be used. One of: + * <ul> + * <li>{@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}</li> + * <li>{@link VolumeProvider#VOLUME_CONTROL_RELATIVE}</li> + * <li>{@link VolumeProvider#VOLUME_CONTROL_FIXED}</li> + * </ul> + * + * @return The type of volume control that may be used with this + * session. + */ + public int getVolumeControl() { + return mVolumeControl; + } + + /** + * Get the maximum volume that may be set for this session. + * + * @return The maximum allowed volume where this session is playing. + */ + public int getMaxVolume() { + return mMaxVolume; + } + + /** + * Get the current volume for this session. + * + * @return The current volume where this session is playing. + */ + public int getCurrentVolume() { + return mCurrentVolume; + } + } + private final static class CallbackStub extends ISessionControllerCallback.Stub { private final WeakReference<MediaController> mController; |