VolumeProvider
public
abstract
class
VolumeProvider
extends Object
java.lang.Object | |
↳ | android.media.VolumeProvider |
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
setCurrentVolume(int)
each time the volume being provided changes.
You can set a volume provider on a session by calling
MediaSession#setPlaybackToRemote
.
Summary
Constants | |
---|---|
int |
VOLUME_CONTROL_ABSOLUTE
The volume control uses an absolute value. |
int |
VOLUME_CONTROL_FIXED
The volume is fixed and can not be modified. |
int |
VOLUME_CONTROL_RELATIVE
The volume control uses relative adjustment via
|
Public constructors | |
---|---|
VolumeProvider(int volumeControl, int maxVolume, int currentVolume)
Creates a new volume provider for handling volume events. |
|
VolumeProvider(int volumeControl, int maxVolume, int currentVolume, String volumeControlId)
Creates a new volume provider for handling volume events. |
Public methods | |
---|---|
final
int
|
getCurrentVolume()
Gets the current volume. |
final
int
|
getMaxVolume()
Gets the maximum volume this provider allows. |
final
int
|
getVolumeControl()
Gets the volume control type that this volume provider uses. |
final
String
|
getVolumeControlId()
Gets the |
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. |
final
void
|
setCurrentVolume(int currentVolume)
Notifies the system that the current volume has been changed. |
Inherited methods | |
---|---|
Constants
VOLUME_CONTROL_ABSOLUTE
public static final int VOLUME_CONTROL_ABSOLUTE
The volume control uses an absolute value. It may be adjusted using
onAdjustVolume(int)
or set directly using
onSetVolumeTo(int)
.
Constant Value: 2 (0x00000002)
VOLUME_CONTROL_FIXED
public static final int VOLUME_CONTROL_FIXED
The volume is fixed and can not be modified. Requests to change volume should be ignored.
Constant Value: 0 (0x00000000)
VOLUME_CONTROL_RELATIVE
public static final int VOLUME_CONTROL_RELATIVE
The volume control uses relative adjustment via
onAdjustVolume(int)
. Attempts to set the volume to a specific
value should be ignored.
Constant Value: 1 (0x00000001)
Public constructors
VolumeProvider
public VolumeProvider (int volumeControl, int maxVolume, int currentVolume)
Creates a new volume provider for handling volume events.
Parameters | |
---|---|
volumeControl |
int : See getVolumeControl() .
Value is VOLUME_CONTROL_FIXED , VOLUME_CONTROL_RELATIVE , or VOLUME_CONTROL_ABSOLUTE |
maxVolume |
int : The maximum allowed volume. |
currentVolume |
int : The current volume on the output. |
VolumeProvider
public VolumeProvider (int volumeControl, int maxVolume, int currentVolume, String volumeControlId)
Creates a new volume provider for handling volume events.
Parameters | |
---|---|
volumeControl |
int : See getVolumeControl() .
Value is VOLUME_CONTROL_FIXED , VOLUME_CONTROL_RELATIVE , or VOLUME_CONTROL_ABSOLUTE |
maxVolume |
int : The maximum allowed volume. |
currentVolume |
int : The current volume on the output. |
volumeControlId |
String : See getVolumeControlId() .
This value may be null . |
Public methods
getCurrentVolume
public final int getCurrentVolume ()
Gets the current volume. This will be the last value set by
setCurrentVolume(int)
.
Returns | |
---|---|
int |
The current volume. |
getMaxVolume
public final int getMaxVolume ()
Gets the maximum volume this provider allows.
Returns | |
---|---|
int |
The max allowed volume. |
getVolumeControl
public final int getVolumeControl ()
Gets the volume control type that this volume provider uses.
One of VOLUME_CONTROL_FIXED
, VOLUME_CONTROL_ABSOLUTE
, or VOLUME_CONTROL_RELATIVE
.
Returns | |
---|---|
int |
The volume control type for this volume provider
Value is VOLUME_CONTROL_FIXED , VOLUME_CONTROL_RELATIVE , or VOLUME_CONTROL_ABSOLUTE |
getVolumeControlId
public final String getVolumeControlId ()
Gets the routing controller id
of the RoutingController
associated with this volume provider, or null if unset.
This id allows mapping this volume provider to a routing controller, which provides information about the media route and allows controlling its volume.
Returns | |
---|---|
String |
onAdjustVolume
public void onAdjustVolume (int direction)
Override to handle requests to adjust the volume of the current output.
Direction will be one of AudioManager#ADJUST_LOWER
,
AudioManager#ADJUST_RAISE
, AudioManager#ADJUST_SAME
.
After the volume has been modified setCurrentVolume(int)
must be
called to notify the system.
Parameters | |
---|---|
direction |
int : The direction to change the volume in. |
onSetVolumeTo
public void onSetVolumeTo (int volume)
Override to handle requests to set the volume of the current output.
After the volume has been modified setCurrentVolume(int)
must be
called to notify the system.
Parameters | |
---|---|
volume |
int : The volume to set the output to. |
setCurrentVolume
public final void setCurrentVolume (int currentVolume)
Notifies the system that the current volume has been changed. This must be called every time the volume changes to ensure it is displayed properly.
Parameters | |
---|---|
currentVolume |
int : The current volume on the output. |