FileDocCategorySizeDatePackage
VolumeProviderCompat.javaAPI DocAndroid 5.1 API5240Thu Mar 12 22:22:56 GMT 2015android.support.v4.media

VolumeProviderCompat

public abstract class VolumeProviderCompat extends Object
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. You can set a volume provider on a session by calling {@link MediaSessionCompat#setPlaybackToRemote}.

Fields Summary
public static final int
VOLUME_CONTROL_FIXED
The volume is fixed and can not be modified. Requests to change volume should be ignored.
public static final int
VOLUME_CONTROL_RELATIVE
The volume control uses relative adjustment via {@link #onAdjustVolume(int)}. Attempts to set the volume to a specific value should be ignored.
public static final int
VOLUME_CONTROL_ABSOLUTE
The volume control uses an absolute value. It may be adjusted using {@link #onAdjustVolume(int)} or set directly using {@link #onSetVolumeTo(int)}.
private final int
mControlType
private final int
mMaxVolume
private int
mCurrentVolume
private Callback
mCallback
private Object
mVolumeProviderObj
Constructors Summary
public VolumeProviderCompat(int volumeControl, int maxVolume, int currentVolume)
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.

param
volumeControl The method for controlling volume that is used by this provider.
param
maxVolume The maximum allowed volume.
param
currentVolume The current volume.


                                                                     
           
        mControlType = volumeControl;
        mMaxVolume = maxVolume;
        mCurrentVolume = currentVolume;
    
Methods Summary
public final intgetCurrentVolume()
Get the current volume of the provider.

return
The current volume.

        return mCurrentVolume;
    
public final intgetMaxVolume()
Get the maximum volume this provider allows.

return
The max allowed volume.

        return mMaxVolume;
    
public final intgetVolumeControl()
Get the volume control type that this volume provider uses.

return
The volume control type for this volume provider

        return mControlType;
    
public java.lang.ObjectgetVolumeProvider()
Gets the underlying framework {@link android.media.VolumeProvider} object.

This method is only supported on API 21+.

return
An equivalent {@link android.media.VolumeProvider} object, or null if none.

        if (mVolumeProviderObj != null || Build.VERSION.SDK_INT < 21) {
            return mVolumeProviderObj;
        }

        mVolumeProviderObj = VolumeProviderCompatApi21.createVolumeProvider(
                mControlType, mMaxVolume, mCurrentVolume, new VolumeProviderCompatApi21.Delegate() {

            @Override
            public void onSetVolumeTo(int volume) {
                VolumeProviderCompat.this.onSetVolumeTo(volume);
            }

            @Override
            public void onAdjustVolume(int direction) {
                VolumeProviderCompat.this.onAdjustVolume(direction);
            }
        });
        return mVolumeProviderObj;
    
public voidonAdjustVolume(int direction)
Override to handle requests to adjust the volume of the current output.

param
direction The direction to adjust the volume in.

    
public voidonSetVolumeTo(int volume)
Override to handle requests to set the volume of the current output.

param
volume The volume to set the output to.

    
public voidsetCallback(android.support.v4.media.VolumeProviderCompat$Callback callback)
Sets a callback to receive volume changes.

Used internally by the support library.

        mCallback = callback;
    
public final voidsetCurrentVolume(int currentVolume)
Set the current volume and notify the system that the volume has been changed.

param
currentVolume The current volume of the output.

        if (mCallback != null) {
            mCallback.onVolumeChanged(this);
        }