public abstract class VolumeProvider extends Object
setCurrentVolume(int)
each time the volume being provided changes.
You can set a volume provider on a session by calling
MediaSession.setPlaybackToRemote(android.media.VolumeProvider)
.
Modifier and Type | Class and Description |
---|---|
static class |
VolumeProvider.Callback
Listens for changes to the volume.
|
static interface |
VolumeProvider.ControlType |
Modifier and Type | Field and Description |
---|---|
static int |
VOLUME_CONTROL_ABSOLUTE
The volume control uses an absolute value.
|
static int |
VOLUME_CONTROL_FIXED
The volume is fixed and can not be modified.
|
static int |
VOLUME_CONTROL_RELATIVE
The volume control uses relative adjustment via
onAdjustVolume(int) . |
Constructor and Description |
---|
VolumeProvider(int volumeControl,
int maxVolume,
int currentVolume)
Create a new volume provider for handling volume events.
|
Modifier and Type | Method and Description |
---|---|
int |
getCurrentVolume()
Gets the current volume.
|
int |
getMaxVolume()
Get the maximum volume this provider allows.
|
int |
getVolumeControl()
Get the volume control type that this volume provider uses.
|
void |
onAdjustVolume(int direction)
Override to handle requests to adjust the volume of the current output.
|
void |
onSetVolumeTo(int volume)
Override to handle requests to set the volume of the current output.
|
void |
setCallback(VolumeProvider.Callback callback)
Sets a callback to receive volume changes.
|
void |
setCurrentVolume(int currentVolume)
Notify the system that the current volume has been changed.
|
public static final int VOLUME_CONTROL_FIXED
public static final int VOLUME_CONTROL_RELATIVE
onAdjustVolume(int)
. Attempts to set the volume to a specific
value should be ignored.public static final int VOLUME_CONTROL_ABSOLUTE
onAdjustVolume(int)
or set directly using
onSetVolumeTo(int)
.public VolumeProvider(int volumeControl, int maxVolume, int currentVolume)
volumeControl
- The method for controlling volume that is used by
this provider.maxVolume
- The maximum allowed volume.currentVolume
- The current volume on the output.public final int getVolumeControl()
public final int getMaxVolume()
public final int getCurrentVolume()
setCurrentVolume(int)
.public final void setCurrentVolume(int currentVolume)
currentVolume
- The current volume on the output.public void onSetVolumeTo(int volume)
setCurrentVolume(int)
must be
called to notify the system.volume
- The volume to set the output to.public void onAdjustVolume(int direction)
AudioManager.ADJUST_LOWER
,
AudioManager.ADJUST_RAISE
, AudioManager.ADJUST_SAME
.
After the volume has been modified setCurrentVolume(int)
must be
called to notify the system.direction
- The direction to change the volume in.public void setCallback(VolumeProvider.Callback callback)