FileDocCategorySizeDatePackage
VolumeProvider.javaAPI DocAndroid 5.1 API4766Thu Mar 12 22:22:30 GMT 2015android.media

VolumeProvider

public abstract class VolumeProvider 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. The provider must call {@link #setCurrentVolume(int)} each time the volume being provided changes.

You can set a volume provider on a session by calling {@link MediaSession#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
Constructors Summary
public VolumeProvider(int volumeControl, int maxVolume, int currentVolume)
Create a new volume provider for handling volume events. You must specify 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.


                                                                              
           
        mControlType = volumeControl;
        mMaxVolume = maxVolume;
        mCurrentVolume = currentVolume;
    
Methods Summary
public final intgetCurrentVolume()
Gets the current volume. This will be the last value set by {@link #setCurrentVolume(int)}.

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 voidonAdjustVolume(int direction)
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 voidonSetVolumeTo(int volume)
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.

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

hide

        mCallback = callback;
    
public final voidsetCurrentVolume(int currentVolume)
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.

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