diff options
-rw-r--r-- | api/current.txt | 6 | ||||
-rw-r--r-- | media/java/android/media/MediaRouter.java | 13 | ||||
-rw-r--r-- | media/java/android/media/VolumeProvider.java | 43 | ||||
-rw-r--r-- | media/java/android/media/session/MediaSession.java | 4 |
4 files changed, 39 insertions, 27 deletions
diff --git a/api/current.txt b/api/current.txt index d132ac7b2067..a69a8e5f98a0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15920,13 +15920,13 @@ package android.media { } public abstract class VolumeProvider { - ctor public VolumeProvider(int, int); + ctor public VolumeProvider(int, int, int); + method public final int getCurrentVolume(); method public final int getMaxVolume(); method public final int getVolumeControl(); - method public final void notifyVolumeChanged(); method public void onAdjustVolume(int); - method public abstract int onGetCurrentVolume(); method public void onSetVolumeTo(int); + method public final void setCurrentVolume(int); field public static final int VOLUME_CONTROL_ABSOLUTE = 2; // 0x2 field public static final int VOLUME_CONTROL_FIXED = 0; // 0x0 field public static final int VOLUME_CONTROL_RELATIVE = 1; // 0x1 diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 6a4bf076af77..958ffab3c39d 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -2131,7 +2131,7 @@ public class MediaRouter { if (mVolume != volume) { mVolume = volume; if (mSvp != null) { - mSvp.notifyVolumeChanged(); + mSvp.setCurrentVolume(mVolume); } dispatchRouteVolumeChanged(this); if (mGroup != null) { @@ -2217,7 +2217,7 @@ public class MediaRouter { // Only register a new listener if necessary if (mSvp == null || mSvp.getVolumeControl() != volumeControl || mSvp.getMaxVolume() != mVolumeMax) { - mSvp = new SessionVolumeProvider(volumeControl, mVolumeMax); + mSvp = new SessionVolumeProvider(volumeControl, mVolumeMax, mVolume); session.setPlaybackToRemote(mSvp); } } else { @@ -2231,13 +2231,8 @@ public class MediaRouter { class SessionVolumeProvider extends VolumeProvider { - public SessionVolumeProvider(int volumeControl, int maxVolume) { - super(volumeControl, maxVolume); - } - - @Override - public int onGetCurrentVolume() { - return mVcb == null ? 0 : mVcb.route.mVolume; + public SessionVolumeProvider(int volumeControl, int maxVolume, int currentVolume) { + super(volumeControl, maxVolume, currentVolume); } @Override diff --git a/media/java/android/media/VolumeProvider.java b/media/java/android/media/VolumeProvider.java index 9bda1d4bf21e..5d1e0041585c 100644 --- a/media/java/android/media/VolumeProvider.java +++ b/media/java/android/media/VolumeProvider.java @@ -19,7 +19,9 @@ import android.media.session.MediaSession; /** * Handles requests to adjust or set the volume on a session. This is also used - * to push volume updates back to the session after a request has been handled. + * to push volume updates back to the session. The provider must call + * {@link #setCurrentVolume(int)} each time the volume being provided changes. + * <p> * You can set a volume provider on a session by calling * {@link MediaSession#setPlaybackToRemote}. */ @@ -46,29 +48,26 @@ public abstract class VolumeProvider { private final int mControlType; private final int mMaxVolume; + private int mCurrentVolume; private Callback mCallback; /** * Create a new volume provider for handling volume events. You must specify - * the type of volume control and the maximum volume that can be used. + * the type of volume control, the maximum volume that can be used, and the + * current volume on the output. * * @param volumeControl The method for controlling volume that is used by * this provider. * @param maxVolume The maximum allowed volume. + * @param currentVolume The current volume on the output. */ - public VolumeProvider(int volumeControl, int maxVolume) { + public VolumeProvider(int volumeControl, int maxVolume, int currentVolume) { mControlType = volumeControl; mMaxVolume = maxVolume; + mCurrentVolume = currentVolume; } /** - * Get the current volume of the remote playback. - * - * @return The current volume. - */ - public abstract int onGetCurrentVolume(); - - /** * Get the volume control type that this volume provider uses. * * @return The volume control type for this volume provider @@ -87,9 +86,23 @@ public abstract class VolumeProvider { } /** - * Notify the system that the volume has been changed. + * Gets the current volume. This will be the last value set by + * {@link #setCurrentVolume(int)}. + * + * @return The current volume. */ - public final void notifyVolumeChanged() { + public final int getCurrentVolume() { + return mCurrentVolume; + } + + /** + * Notify the system that the current volume has been changed. This must be + * called every time the volume changes to ensure it is displayed properly. + * + * @param currentVolume The current volume on the output. + */ + public final void setCurrentVolume(int currentVolume) { + mCurrentVolume = currentVolume; if (mCallback != null) { mCallback.onVolumeChanged(this); } @@ -97,6 +110,8 @@ public abstract class VolumeProvider { /** * Override to handle requests to set the volume of the current output. + * After the volume has been modified {@link #setCurrentVolume} must be + * called to notify the system. * * @param volume The volume to set the output to. */ @@ -107,7 +122,9 @@ public abstract class VolumeProvider { * Override to handle requests to adjust the volume of the current output. * Direction will be one of {@link AudioManager#ADJUST_LOWER}, * {@link AudioManager#ADJUST_RAISE}, {@link AudioManager#ADJUST_SAME}. - * + * After the volume has been modified {@link #setCurrentVolume} must be + * called to notify the system. + * * @param direction The direction to change the volume in. */ public void onAdjustVolume(int direction) { diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java index 095f88578e28..8cb039ab89b3 100644 --- a/media/java/android/media/session/MediaSession.java +++ b/media/java/android/media/session/MediaSession.java @@ -300,7 +300,7 @@ public final class MediaSession { try { mBinder.setPlaybackToRemote(volumeProvider.getVolumeControl(), volumeProvider.getMaxVolume()); - mBinder.setCurrentVolume(volumeProvider.onGetCurrentVolume()); + mBinder.setCurrentVolume(volumeProvider.getCurrentVolume()); } catch (RemoteException e) { Log.wtf(TAG, "Failure in setPlaybackToRemote.", e); } @@ -478,7 +478,7 @@ public final class MediaSession { return; } try { - mBinder.setCurrentVolume(provider.onGetCurrentVolume()); + mBinder.setCurrentVolume(provider.getCurrentVolume()); } catch (RemoteException e) { Log.e(TAG, "Error in notifyVolumeChanged", e); } |