# VolumeProvider

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Constants](https://developer.android.com/reference/android/media/VolumeProvider#constants)\|[Ctors](https://developer.android.com/reference/android/media/VolumeProvider#pubctors)\|[Methods](https://developer.android.com/reference/android/media/VolumeProvider#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/media/VolumeProvider#inhmethods)  

# VolumeProvider

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/media/VolumeProvider "View this page in Kotlin")\|Java

`
public


abstract
class
VolumeProvider
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.VolumeProvider |

<br />

*** ** * ** ***

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)](https://developer.android.com/reference/android/media/VolumeProvider#setCurrentVolume(int))each time the volume being provided changes.

You can set a volume provider on a session by calling[MediaSession.setPlaybackToRemote](https://developer.android.com/reference/android/media/session/MediaSession#setPlaybackToRemote(android.media.VolumeProvider)).

## Summary

|                                                                                                                                         ### Constants                                                                                                                                          ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_ABSOLUTE) The volume control uses an absolute value.                                                                                                                      |
| `int` | [VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_FIXED) The volume is fixed and can not be modified.                                                                                                                          |
| `int` | [VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_RELATIVE) The volume control uses relative adjustment via[onAdjustVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#onAdjustVolume(int)). |

|                                                                                                                                                                  ### Public constructors                                                                                                                                                                   ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[VolumeProvider](https://developer.android.com/reference/android/media/VolumeProvider#VolumeProvider(int,%20int,%20int))`(int volumeControl, int maxVolume, int currentVolume) ` Creates a new volume provider for handling volume events.                                                                                                           |
| ` `[VolumeProvider](https://developer.android.com/reference/android/media/VolumeProvider#VolumeProvider(int,%20int,%20int,%20java.lang.String))`(int volumeControl, int maxVolume, int currentVolume, `[String](https://developer.android.com/reference/java/lang/String)` volumeControlId) ` Creates a new volume provider for handling volume events. |

|                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                            ||
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` final int`                                                                | ` `[getCurrentVolume](https://developer.android.com/reference/android/media/VolumeProvider#getCurrentVolume())`() ` Gets the current volume.                                                                                                                                                                                                                                                                                |
| ` final int`                                                                | ` `[getMaxVolume](https://developer.android.com/reference/android/media/VolumeProvider#getMaxVolume())`() ` Gets the maximum volume this provider allows.                                                                                                                                                                                                                                                                   |
| ` final int`                                                                | ` `[getVolumeControl](https://developer.android.com/reference/android/media/VolumeProvider#getVolumeControl())`() ` Gets the volume control type that this volume provider uses.                                                                                                                                                                                                                                            |
| ` final `[String](https://developer.android.com/reference/java/lang/String) | ` `[getVolumeControlId](https://developer.android.com/reference/android/media/VolumeProvider#getVolumeControlId())`() ` Gets the[routing controller id](https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getId())of the[RoutingController](https://developer.android.com/reference/android/media/MediaRouter2.RoutingController)associated with this volume provider, or null if unset. |
| ` void`                                                                     | ` `[onAdjustVolume](https://developer.android.com/reference/android/media/VolumeProvider#onAdjustVolume(int))`(int direction) ` Override to handle requests to adjust the volume of the current output.                                                                                                                                                                                                                     |
| ` void`                                                                     | ` `[onSetVolumeTo](https://developer.android.com/reference/android/media/VolumeProvider#onSetVolumeTo(int))`(int volume) ` Override to handle requests to set the volume of the current output.                                                                                                                                                                                                                             |
| ` final void`                                                               | ` `[setCurrentVolume](https://developer.android.com/reference/android/media/VolumeProvider#setCurrentVolume(int))`(int currentVolume) ` Notifies the system that the current volume has been changed.                                                                                                                                                                                                                       |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### VOLUME_CONTROL_ABSOLUTE

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int VOLUME_CONTROL_ABSOLUTE
```

The volume control uses an absolute value. It may be adjusted using[onAdjustVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#onAdjustVolume(int))or set directly using[onSetVolumeTo(int)](https://developer.android.com/reference/android/media/VolumeProvider#onSetVolumeTo(int)).

<br />

Constant Value: 2 (0x00000002)  

### VOLUME_CONTROL_FIXED

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int VOLUME_CONTROL_FIXED
```

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

<br />

Constant Value: 0 (0x00000000)  

### VOLUME_CONTROL_RELATIVE

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int VOLUME_CONTROL_RELATIVE
```

The volume control uses relative adjustment via[onAdjustVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#onAdjustVolume(int)). Attempts to set the volume to a specific value should be ignored.

<br />

Constant Value: 1 (0x00000001)

## Public constructors

### VolumeProvider

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VolumeProvider (int volumeControl, 
                int maxVolume, 
                int currentVolume)
```

Creates a new volume provider for handling volume events.

<br />

|                                                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                                                           ||
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `volumeControl` | `int`: See[getVolumeControl()](https://developer.android.com/reference/android/media/VolumeProvider#getVolumeControl()). Value is[VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_FIXED),[VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_RELATIVE), or[VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_ABSOLUTE) <br /> |
| `maxVolume`     | `int`: The maximum allowed volume. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `currentVolume` | `int`: The current volume on the output. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

### VolumeProvider

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VolumeProvider (int volumeControl, 
                int maxVolume, 
                int currentVolume, 
                String volumeControlId)
```

Creates a new volume provider for handling volume events.

<br />

|                                                                                                                                                                                                                                                           Parameters                                                                                                                                                                                                                                                            ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `volumeControl`   | `int`: See[getVolumeControl()](https://developer.android.com/reference/android/media/VolumeProvider#getVolumeControl()). Value is[VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_FIXED),[VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_RELATIVE), or[VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_ABSOLUTE) <br /> |
| `maxVolume`       | `int`: The maximum allowed volume. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `currentVolume`   | `int`: The current volume on the output. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `volumeControlId` | `String`: See[getVolumeControlId()](https://developer.android.com/reference/android/media/VolumeProvider#getVolumeControlId()). This value may be`null`. <br />                                                                                                                                                                                                                                                                                                                                              |

## Public methods

### getCurrentVolume

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getCurrentVolume ()
```

Gets the current volume. This will be the last value set by[setCurrentVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#setCurrentVolume(int)).

<br />

|              Returns              ||
|-------|----------------------------|
| `int` | The current volume. <br /> |

### getMaxVolume

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getMaxVolume ()
```

Gets the maximum volume this provider allows.

<br />

|                Returns                ||
|-------|--------------------------------|
| `int` | The max allowed volume. <br /> |

### getVolumeControl

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final int getVolumeControl ()
```

Gets the volume control type that this volume provider uses.

One of[VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_FIXED),[VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_ABSOLUTE), or[VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_RELATIVE).

<br />

|                                                                                                                                                                                                                   Returns                                                                                                                                                                                                                   ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | The volume control type for this volume provider Value is[VOLUME_CONTROL_FIXED](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_FIXED),[VOLUME_CONTROL_RELATIVE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_RELATIVE), or[VOLUME_CONTROL_ABSOLUTE](https://developer.android.com/reference/android/media/VolumeProvider#VOLUME_CONTROL_ABSOLUTE) <br /> |

### getVolumeControlId

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final String getVolumeControlId ()
```

Gets the[routing controller id](https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getId())of the[RoutingController](https://developer.android.com/reference/android/media/MediaRouter2.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.

<br />

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### onAdjustVolume

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onAdjustVolume (int direction)
```

Override to handle requests to adjust the volume of the current output. Direction will be one of[AudioManager.ADJUST_LOWER](https://developer.android.com/reference/android/media/AudioManager#ADJUST_LOWER),[AudioManager.ADJUST_RAISE](https://developer.android.com/reference/android/media/AudioManager#ADJUST_RAISE),[AudioManager.ADJUST_SAME](https://developer.android.com/reference/android/media/AudioManager#ADJUST_SAME). After the volume has been modified[setCurrentVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#setCurrentVolume(int))must be called to notify the system.

<br />

|                            Parameters                             ||
|-------------|------------------------------------------------------|
| `direction` | `int`: The direction to change the volume in. <br /> |

### onSetVolumeTo

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onSetVolumeTo (int volume)
```

Override to handle requests to set the volume of the current output. After the volume has been modified[setCurrentVolume(int)](https://developer.android.com/reference/android/media/VolumeProvider#setCurrentVolume(int))must be called to notify the system.

<br />

|                        Parameters                        ||
|----------|------------------------------------------------|
| `volume` | `int`: The volume to set the output to. <br /> |

### setCurrentVolume

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void setCurrentVolume (int currentVolume)
```

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.

<br />

|                            Parameters                            ||
|-----------------|-------------------------------------------------|
| `currentVolume` | `int`: The current volume on the output. <br /> |