UniversalVolume

UniversalVolume is a singleton class that manages media volume. It supports popular and also exotic Android devices that may use non-standard volume APIs. UniversalVolume manages media volume AudioManager.STREAM_MUSIC only. Make sure to call initialize function before using any other function. Use UniversalVolume.instance to access the singleton instance and call any methods on it.

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns the maximum volume as an integer.

Link copied to clipboard

Returns the minimum volume as an integer.

Link copied to clipboard
val volume: Int?

Returns the current volume as an integer between 0 and maxVolume. The maxVolume depends on each device.

Link copied to clipboard

Returns the current volume as a double between 0 and 1. The range is the same for all devices.

Functions

Link copied to clipboard

Adds a listener to the list of volume change listeners.

Link copied to clipboard
fun dispose()

Disposes the UniversalVolume instance.

Link copied to clipboard
fun initialize(context: Context)

Initializes the UniversalVolume instance with the given context.

Link copied to clipboard

Removes a listener from the list of volume change listeners.

Link copied to clipboard
fun setVolume(volume: Int, showVolumeBar: Boolean = false): Boolean

Sets the volume to the given volume value. If showVolumeBar is true, shows the volume bar.

Link copied to clipboard
fun setVolumeToPercentage(percentage: Double, showVolumeBar: Boolean = false): Boolean

Sets the volume to the given percentage value. If showVolumeBar is true, shows the volume bar.