VolumeProvider
abstract class VolumeProvider
kotlin.Any | |
↳ | 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 | |
---|---|
static Int |
The volume control uses an absolute value. |
static Int |
The volume is fixed and can not be modified. |
static Int |
The volume control uses relative adjustment via |
Public constructors | |
---|---|
VolumeProvider(volumeControl: Int, maxVolume: Int, currentVolume: Int) Creates a new volume provider for handling volume events. |
|
VolumeProvider(volumeControl: Int, maxVolume: Int, currentVolume: Int, volumeControlId: String?) Creates a new volume provider for handling volume events. |
Public methods | |
---|---|
Int |
Gets the current volume. |
Int |
Gets the maximum volume this provider allows. |
Int |
Gets the volume control type that this volume provider uses. |
String? |
Gets the |
open Unit |
onAdjustVolume(direction: Int) Override to handle requests to adjust the volume of the current output. |
open Unit |
onSetVolumeTo(volume: Int) Override to handle requests to set the volume of the current output. |
Unit |
setCurrentVolume(currentVolume: Int) Notifies the system that the current volume has been changed. |
Constants
VOLUME_CONTROL_ABSOLUTE
static val VOLUME_CONTROL_ABSOLUTE: Int
The volume control uses an absolute value. It may be adjusted using onAdjustVolume(int)
or set directly using onSetVolumeTo(int)
.
Value: 2
VOLUME_CONTROL_FIXED
static val VOLUME_CONTROL_FIXED: Int
The volume is fixed and can not be modified. Requests to change volume should be ignored.
Value: 0
VOLUME_CONTROL_RELATIVE
static val VOLUME_CONTROL_RELATIVE: Int
The volume control uses relative adjustment via onAdjustVolume(int)
. Attempts to set the volume to a specific value should be ignored.
Value: 1
Public constructors
VolumeProvider
VolumeProvider(
volumeControl: Int,
maxVolume: Int,
currentVolume: Int)
Creates a new volume provider for handling volume events.
Parameters | |
---|---|
volumeControl |
Int: See getVolumeControl() . Value is android.media.VolumeProvider#VOLUME_CONTROL_FIXED , android.media.VolumeProvider#VOLUME_CONTROL_RELATIVE , or android.media.VolumeProvider#VOLUME_CONTROL_ABSOLUTE |
maxVolume |
Int: The maximum allowed volume. |
currentVolume |
Int: The current volume on the output. |
VolumeProvider
VolumeProvider(
volumeControl: Int,
maxVolume: Int,
currentVolume: Int,
volumeControlId: String?)
Creates a new volume provider for handling volume events.
Parameters | |
---|---|
volumeControl |
Int: See getVolumeControl() . Value is android.media.VolumeProvider#VOLUME_CONTROL_FIXED , android.media.VolumeProvider#VOLUME_CONTROL_RELATIVE , or android.media.VolumeProvider#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
fun getCurrentVolume(): Int
Gets the current volume. This will be the last value set by setCurrentVolume(int)
.
Return | |
---|---|
Int |
The current volume. |
getMaxVolume
fun getMaxVolume(): Int
Gets the maximum volume this provider allows.
Return | |
---|---|
Int |
The max allowed volume. |
getVolumeControl
fun getVolumeControl(): Int
Gets the volume control type that this volume provider uses.
One of VOLUME_CONTROL_FIXED
, VOLUME_CONTROL_ABSOLUTE
, or VOLUME_CONTROL_RELATIVE
.
Return | |
---|---|
Int |
The volume control type for this volume provider Value is android.media.VolumeProvider#VOLUME_CONTROL_FIXED , android.media.VolumeProvider#VOLUME_CONTROL_RELATIVE , or android.media.VolumeProvider#VOLUME_CONTROL_ABSOLUTE |
getVolumeControlId
fun getVolumeControlId(): String?
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.
onAdjustVolume
open fun onAdjustVolume(direction: Int): Unit
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
must be called to notify the system.
Parameters | |
---|---|
direction |
Int: The direction to change the volume in. |
onSetVolumeTo
open fun onSetVolumeTo(volume: Int): Unit
Override to handle requests to set the volume of the current output. After the volume has been modified setCurrentVolume
must be called to notify the system.
Parameters | |
---|---|
volume |
Int: The volume to set the output to. |
setCurrentVolume
fun setCurrentVolume(currentVolume: Int): Unit
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. |