Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

VolumeProviderCompat

abstract class VolumeProviderCompat
kotlin.Any
   ↳ androidx.media.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 MediaSessionCompat#setPlaybackToRemote.

Summary

Nested classes
abstract

Listens for changes to the volume.

Constants
static Int

The volume is fixed and can not be modified.

static Int

The volume control uses relative adjustment via onAdjustVolume(int).

static Int

The volume control uses an absolute value.

Public constructors
<init>(volumeControl: Int, maxVolume: Int, currentVolume: Int)

Create a new volume provider for handling volume events.

Public methods
open Unit
onSetVolumeTo(volume: Int)

Override to handle requests to set the volume of the current output.

Int

Get the current volume of the provider.

open Unit

Sets a callback to receive volume changes.

open Any!

Gets the underlying framework android.media.VolumeProvider object.

Int

Get the maximum volume this provider allows.

Unit
setCurrentVolume(currentVolume: Int)

Set the current volume and notify the system that the volume has been changed.

open Unit
onAdjustVolume(direction: Int)

Override to handle requests to adjust the volume of the current output.

Int

Get the volume control type that this volume provider uses.

Constants

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

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

Public constructors

<init>

VolumeProviderCompat(volumeControl: Int, maxVolume: Int, currentVolume: Int)

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
volumeControl Int: The method for controlling volume that is used by this provider.
maxVolume Int: The maximum allowed volume.
currentVolume Int: The current volume.

Public methods

onSetVolumeTo

open fun onSetVolumeTo(volume: Int): Unit

Override to handle requests to set the volume of the current output.

Parameters
volume Int: The volume to set the output to.

getCurrentVolume

fun getCurrentVolume(): Int

Get the current volume of the provider.

Return
Int: The current volume.

setCallback

open fun setCallback(callback: VolumeProviderCompat.Callback!): Unit

Sets a callback to receive volume changes.

Used internally by the support library.

getVolumeProvider

open fun getVolumeProvider(): Any!

Gets the underlying framework android.media.VolumeProvider object.

This method is only supported on API 21+.

Return
Any!: An equivalent android.media.VolumeProvider object, or null if none.

getMaxVolume

fun getMaxVolume(): Int

Get the maximum volume this provider allows.

Return
Int: The max allowed volume.

setCurrentVolume

fun setCurrentVolume(currentVolume: Int): Unit

Set the current volume and notify the system that the volume has been changed.

Parameters
currentVolume Int: The current volume of the output.

onAdjustVolume

open fun onAdjustVolume(direction: Int): Unit

Override to handle requests to adjust the volume of the current output.

Parameters
direction Int: The direction to adjust the volume in.

getVolumeControl

fun getVolumeControl(): Int

Get the volume control type that this volume provider uses.

Return
Int: The volume control type for this volume provider