VolumeProviderCompat
public abstract class VolumeProviderCompat
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 setPlaybackToRemote.
Summary
Nested types |
|---|
public abstract class VolumeProviderCompat.CallbackListens for changes to the volume. |
Constants |
|
|---|---|
static final int |
The volume control uses an absolute value. |
static final int |
The volume is fixed and can not be modified. |
static final int |
The volume control uses relative adjustment via |
Public constructors |
|---|
VolumeProviderCompat(Create a new volume provider for handling volume events. |
Public methods |
|
|---|---|
final int |
Get the current volume of the provider. |
final int |
Get the maximum volume this provider allows. |
final int |
Get the volume control type that this volume provider uses. |
Object |
Gets the underlying framework |
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(VolumeProviderCompat.Callback callback)Sets a callback to receive volume changes. |
final void |
setCurrentVolume(int currentVolume)Set the current volume and notify the system that the volume has been changed. |
Constants
VOLUME_CONTROL_ABSOLUTE
public static final int VOLUME_CONTROL_ABSOLUTE = 2
The volume control uses an absolute value. It may be adjusted using onAdjustVolume or set directly using onSetVolumeTo.
VOLUME_CONTROL_FIXED
public static final int VOLUME_CONTROL_FIXED = 0
The volume is fixed and can not be modified. Requests to change volume should be ignored.
VOLUME_CONTROL_RELATIVE
public static final int VOLUME_CONTROL_RELATIVE = 1
The volume control uses relative adjustment via onAdjustVolume. Attempts to set the volume to a specific value should be ignored.
Public constructors
VolumeProviderCompat
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.
| Parameters | |
|---|---|
int volumeControl |
The method for controlling volume that is used by this provider. |
int maxVolume |
The maximum allowed volume. |
int currentVolume |
The current volume. |
Public methods
getCurrentVolume
public final int getCurrentVolume()
Get the current volume of the provider.
| Returns | |
|---|---|
int |
The current volume. |
getMaxVolume
public final int getMaxVolume()
Get the maximum volume this provider allows.
| Returns | |
|---|---|
int |
The max allowed volume. |
getVolumeControl
public final int getVolumeControl()
Get the volume control type that this volume provider uses.
| Returns | |
|---|---|
int |
The volume control type for this volume provider |
getVolumeProvider
public Object getVolumeProvider()
Gets the underlying framework android.media.VolumeProvider object.
This method is only supported on API 21+.
| Returns | |
|---|---|
Object |
An equivalent |
onAdjustVolume
public void onAdjustVolume(int direction)
Override to handle requests to adjust the volume of the current output.
| Parameters | |
|---|---|
int direction |
The direction to adjust the volume in. |
onSetVolumeTo
public void onSetVolumeTo(int volume)
Override to handle requests to set the volume of the current output.
| Parameters | |
|---|---|
int volume |
The volume to set the output to. |
setCallback
public void setCallback(VolumeProviderCompat.Callback callback)
Sets a callback to receive volume changes.
Used internally by the support library.
setCurrentVolume
public final void setCurrentVolume(int currentVolume)
Set the current volume and notify the system that the volume has been changed.
| Parameters | |
|---|---|
int currentVolume |
The current volume of the output. |