VolumeProviderCompat

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

Listens for changes to the volume.

Constants

const Int

The volume control uses an absolute value.

const Int

The volume is fixed and can not be modified.

const Int

The volume control uses relative adjustment via onAdjustVolume.

Public constructors

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

Create a new volume provider for handling volume events.

Public functions

Int

Get the current volume of the provider.

Int

Get the maximum volume this provider allows.

Int

Get the volume control type that this volume provider uses.

Any!

Gets the underlying framework android.media.VolumeProvider object.

Unit
onAdjustVolume(direction: Int)

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

Unit
onSetVolumeTo(volume: Int)

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

Unit

Sets a callback to receive volume changes.

Unit
setCurrentVolume(currentVolume: Int)

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

Constants

VOLUME_CONTROL_ABSOLUTE

Added in 1.1.0
const val VOLUME_CONTROL_ABSOLUTE = 2: Int

The volume control uses an absolute value. It may be adjusted using onAdjustVolume or set directly using onSetVolumeTo.

VOLUME_CONTROL_FIXED

Added in 1.1.0
const val VOLUME_CONTROL_FIXED = 0: Int

The volume is fixed and can not be modified. Requests to change volume should be ignored.

VOLUME_CONTROL_RELATIVE

Added in 1.1.0
const val VOLUME_CONTROL_RELATIVE = 1: Int

The volume control uses relative adjustment via onAdjustVolume. Attempts to set the volume to a specific value should be ignored.

Public constructors

VolumeProviderCompat

Added in 1.1.0
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 functions

getCurrentVolume

Added in 1.1.0
fun getCurrentVolume(): Int

Get the current volume of the provider.

Returns
Int

The current volume.

getMaxVolume

Added in 1.1.0
fun getMaxVolume(): Int

Get the maximum volume this provider allows.

Returns
Int

The max allowed volume.

getVolumeControl

Added in 1.1.0
fun getVolumeControl(): Int

Get the volume control type that this volume provider uses.

Returns
Int

The volume control type for this volume provider

getVolumeProvider

Added in 1.1.0
fun getVolumeProvider(): Any!

Gets the underlying framework android.media.VolumeProvider object.

This method is only supported on API 21+.

Returns
Any!

An equivalent android.media.VolumeProvider object, or null if none.

onAdjustVolume

Added in 1.1.0
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.

onSetVolumeTo

Added in 1.1.0
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.

setCallback

Added in 1.1.0
fun setCallback(callback: VolumeProviderCompat.Callback!): Unit

Sets a callback to receive volume changes.

Used internally by the support library.

setCurrentVolume

Added in 1.1.0
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.