AudioManagerCompat
@UnstableApi
class AudioManagerCompat
Compatibility layer for AudioManager with fallbacks for older Android versions.
Summary
Nested types |
|---|
@DocumentedAudio focus gain types. |
Constants |
|
|---|---|
const Int |
AUDIOFOCUS_GAIN = 1Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration. |
const Int |
Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. |
const Int |
Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, during which no other applications, or system components, should play anything. |
const Int |
Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, and where it is acceptable for other audio applications to keep playing after having lowered their output level (also referred to as "ducking"). |
const Int |
AUDIOFOCUS_NONE = 0Used to indicate no audio focus has been gained or lost, or requested. |
Public functions |
|
|---|---|
java-static Int |
abandonAudioFocusRequest(Abandon audio focus. |
synchronized java-static AudioManager! |
getAudioManager(context: Context!)Returns the |
java-static @IntRange(from = 0) Int |
getStreamMaxVolume(Returns the maximum volume index for a particular stream. |
java-static @IntRange(from = 0) Int |
getStreamMinVolume(Returns the minimum volume index for a particular stream. |
java-static Int |
getStreamVolume(audioManager: AudioManager!, @C.StreamType streamType: Int)Returns the current volume for a particular stream. |
java-static Boolean |
isStreamMute(audioManager: AudioManager!, @C.StreamType streamType: Int)Returns whether the given stream is muted. |
java-static Int |
requestAudioFocus(Requests audio focus. |
Constants
AUDIOFOCUS_GAIN
const val AUDIOFOCUS_GAIN = 1: Int
Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.
AUDIOFOCUS_GAIN_TRANSIENT
const val AUDIOFOCUS_GAIN_TRANSIENT = 2: Int
Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. Examples of temporary changes are the playback of driving directions, or an event notification.
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
const val AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE = 4: Int
Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, during which no other applications, or system components, should play anything. Examples of exclusive and transient audio focus requests are voice memo recording and speech recognition, during which the system shouldn't play any notifications, and media playback should have paused.
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
const val AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK = 3: Int
Used to indicate a temporary request of audio focus, anticipated to last a short amount of time, and where it is acceptable for other audio applications to keep playing after having lowered their output level (also referred to as "ducking"). Examples of temporary changes are the playback of driving directions where playback of music in the background is acceptable.
AUDIOFOCUS_NONE
const val AUDIOFOCUS_NONE = 0: Int
Used to indicate no audio focus has been gained or lost, or requested.
Public functions
abandonAudioFocusRequest
java-static fun abandonAudioFocusRequest(
audioManager: AudioManager!,
focusRequest: AudioFocusRequestCompat!
): Int
Abandon audio focus. Causes the previous focus owner, if any, to receive focus.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
focusRequest: AudioFocusRequestCompat! |
The |
getAudioManager
synchronized java-static fun getAudioManager(context: Context!): AudioManager!
Returns the AudioManager.
This method avoids potential threading issues where AudioManager keeps access to the thread it was created on until after this thread is stopped.
It is recommended to use this method from a background thread.
| Returns | |
|---|---|
AudioManager! |
The |
getStreamMaxVolume
java-static fun getStreamMaxVolume(
audioManager: AudioManager!,
@C.StreamType streamType: Int
): @IntRange(from = 0) Int
Returns the maximum volume index for a particular stream.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
@C.StreamType streamType: Int |
The |
getStreamMinVolume
java-static fun getStreamMinVolume(
audioManager: AudioManager!,
@C.StreamType streamType: Int
): @IntRange(from = 0) Int
Returns the minimum volume index for a particular stream.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
@C.StreamType streamType: Int |
The |
getStreamVolume
java-static fun getStreamVolume(audioManager: AudioManager!, @C.StreamType streamType: Int): Int
Returns the current volume for a particular stream.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
@C.StreamType streamType: Int |
The |
| Returns | |
|---|---|
Int |
The current volume of the stream. |
isStreamMute
java-static fun isStreamMute(audioManager: AudioManager!, @C.StreamType streamType: Int): Boolean
Returns whether the given stream is muted.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
@C.StreamType streamType: Int |
The |
| Returns | |
|---|---|
Boolean |
Whether the stream is muted. |
requestAudioFocus
java-static fun requestAudioFocus(
audioManager: AudioManager!,
focusRequest: AudioFocusRequestCompat!
): Int
Requests audio focus. See the AudioFocusRequestCompat for information about the options available to configure your request, and notification of focus gain and loss.
| Parameters | |
|---|---|
audioManager: AudioManager! |
The |
focusRequest: AudioFocusRequestCompat! |
An |