Skip to content

Most visited

Recently visited

navigation

VolumeProvider

public abstract class VolumeProvider
extends Object

java.lang.Object
   ↳ 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 setPlaybackToRemote(VolumeProvider).

Summary

Constants

int VOLUME_CONTROL_ABSOLUTE

The volume control uses an absolute value.

int VOLUME_CONTROL_FIXED

The volume is fixed and can not be modified.

int VOLUME_CONTROL_RELATIVE

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

Public constructors

VolumeProvider(int volumeControl, int maxVolume, int currentVolume)

Create a new volume provider for handling volume events.

Public methods

final int getCurrentVolume()

Gets the current volume.

final int getMaxVolume()

Get the maximum volume this provider allows.

final int getVolumeControl()

Get the volume control type that this volume provider uses.

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.

final void setCurrentVolume(int currentVolume)

Notify the system that the current volume has been changed.

Inherited methods

From class java.lang.Object

Constants

VOLUME_CONTROL_ABSOLUTE

added in API level 21
int VOLUME_CONTROL_ABSOLUTE

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

Constant Value: 2 (0x00000002)

VOLUME_CONTROL_FIXED

added in API level 21
int VOLUME_CONTROL_FIXED

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

Constant Value: 0 (0x00000000)

VOLUME_CONTROL_RELATIVE

added in API level 21
int VOLUME_CONTROL_RELATIVE

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

Constant Value: 1 (0x00000001)

Public constructors

VolumeProvider

added in API level 21
VolumeProvider (int volumeControl, 
                int maxVolume, 
                int currentVolume)

Create a new volume provider for handling volume events. You must specify the type of volume control, the maximum volume that can be used, and the current volume on the output.

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 on the output.

Public methods

getCurrentVolume

added in API level 21
int getCurrentVolume ()

Gets the current volume. This will be the last value set by setCurrentVolume(int).

Returns
int The current volume.

getMaxVolume

added in API level 21
int getMaxVolume ()

Get the maximum volume this provider allows.

Returns
int The max allowed volume.

getVolumeControl

added in API level 21
int getVolumeControl ()

Get the volume control type that this volume provider uses.

Returns
int The volume control type for this volume provider

onAdjustVolume

added in API level 21
void onAdjustVolume (int direction)

Override to handle requests to adjust the volume of the current output. Direction will be one of ADJUST_LOWER, ADJUST_RAISE, ADJUST_SAME. After the volume has been modified setCurrentVolume(int) must be called to notify the system.

Parameters
direction int: The direction to change the volume in.

onSetVolumeTo

added in API level 21
void onSetVolumeTo (int volume)

Override to handle requests to set the volume of the current output. After the volume has been modified setCurrentVolume(int) must be called to notify the system.

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

setCurrentVolume

added in API level 21
void setCurrentVolume (int currentVolume)

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

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.