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.Callback

Listens 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 onAdjustVolume.

Public constructors

VolumeProviderCompat(
    int volumeControl,
    int maxVolume,
    int currentVolume
)

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 android.media.VolumeProvider object.

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

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

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

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

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

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

Added in 1.1.0
public final int getCurrentVolume()

Get the current volume of the provider.

Returns
int

The current volume.

getMaxVolume

Added in 1.1.0
public final int getMaxVolume()

Get the maximum volume this provider allows.

Returns
int

The max allowed volume.

getVolumeControl

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

Added in 1.1.0
public Object getVolumeProvider()

Gets the underlying framework android.media.VolumeProvider object.

This method is only supported on API 21+.

Returns
Object

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

onAdjustVolume

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

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

Added in 1.1.0
public void setCallback(VolumeProviderCompat.Callback callback)

Sets a callback to receive volume changes.

Used internally by the support library.

setCurrentVolume

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