AudioManagerCompat
public
final
class
AudioManagerCompat
extends Object
java.lang.Object | |
↳ | androidx.media.AudioManagerCompat |
Compatibility library for AudioManager
with fallbacks for older platforms.
Summary
Constants | |
---|---|
int |
AUDIOFOCUS_GAIN
Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration. |
int |
AUDIOFOCUS_GAIN_TRANSIENT
Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. |
int |
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
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. |
int |
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
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"). |
Public methods | |
---|---|
static
int
|
abandonAudioFocusRequest(AudioManager audioManager, AudioFocusRequestCompat focusRequest)
Abandon audio focus. |
static
int
|
getStreamMaxVolume(AudioManager audioManager, int streamType)
Returns the maximum volume index for a particular stream. |
static
int
|
getStreamMinVolume(AudioManager audioManager, int streamType)
Returns the minimum volume index for a particular stream. |
static
int
|
requestAudioFocus(AudioManager audioManager, AudioFocusRequestCompat focusRequest)
Requests audio focus. |
Inherited methods | |
---|---|
Constants
AUDIOFOCUS_GAIN
public static final int AUDIOFOCUS_GAIN
Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.
See also:
Constant Value: 1 (0x00000001)
AUDIOFOCUS_GAIN_TRANSIENT
public static final int AUDIOFOCUS_GAIN_TRANSIENT
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.
See also:
Constant Value: 2 (0x00000002)
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
public static final int AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
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.
Constant Value: 4 (0x00000004)
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
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.
See also:
Constant Value: 3 (0x00000003)
Public methods
abandonAudioFocusRequest
public static int abandonAudioFocusRequest (AudioManager audioManager, AudioFocusRequestCompat focusRequest)
Abandon audio focus. Causes the previous focus owner, if any, to receive focus.
Parameters | |
---|---|
audioManager |
AudioManager |
focusRequest |
AudioFocusRequestCompat : the AudioFocusRequestCompat that was used when requesting focus
with requestAudioFocus(AudioManager, AudioFocusRequestCompat) . |
Returns | |
---|---|
int |
AudioManager.AUDIOFOCUS_REQUEST_FAILED or AudioManager.AUDIOFOCUS_REQUEST_GRANTED |
Throws | |
---|---|
IllegalArgumentException |
if passed a null argument |
getStreamMaxVolume
public static int getStreamMaxVolume (AudioManager audioManager, int streamType)
Returns the maximum volume index for a particular stream.
Parameters | |
---|---|
audioManager |
AudioManager |
streamType |
int : The stream type whose maximum volume index is returned. |
Returns | |
---|---|
int |
The maximum valid volume index for the stream. |
getStreamMinVolume
public static int getStreamMinVolume (AudioManager audioManager, int streamType)
Returns the minimum volume index for a particular stream.
Parameters | |
---|---|
audioManager |
AudioManager |
streamType |
int : The stream type whose minimum volume index is returned. |
Returns | |
---|---|
int |
The minimum valid volume index for the stream. |
requestAudioFocus
public static int requestAudioFocus (AudioManager audioManager, AudioFocusRequestCompat focusRequest)
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 |
focusRequest |
AudioFocusRequestCompat : an AudioFocusRequestCompat instance used to configure how focus
is requested. |
Returns | |
---|---|
int |
AudioManager.AUDIOFOCUS_REQUEST_FAILED or AudioManager.AUDIOFOCUS_REQUEST_GRANTED . |
Throws | |
---|---|
NullPointerException |
if passed a null argument |