AudioManagerCompat
public final class AudioManagerCompat
Compatibility library for AudioManager with fallbacks for older platforms.
Summary
Constants |
|
|---|---|
static final int |
AUDIOFOCUS_GAIN = 1Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration. |
static final int |
Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. |
static final 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. |
static final 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"). |
Public methods |
|
|---|---|
static int |
abandonAudioFocusRequest(Abandon audio focus. |
static @IntRange(from = 0) int |
getStreamMaxVolume(@NonNull AudioManager audioManager, int streamType)Returns the maximum volume index for a particular stream. |
static @IntRange(from = 0) int |
getStreamMinVolume(@NonNull AudioManager audioManager, int streamType)Returns the minimum volume index for a particular stream. |
static boolean |
isVolumeFixed(@NonNull AudioManager audioManager)Indicates if the device implements a fixed volume policy. |
static int |
requestAudioFocus(Requests audio focus. |
Constants
AUDIOFOCUS_GAIN
public static final int AUDIOFOCUS_GAIN = 1
Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.
| See also | |
|---|---|
onAudioFocusChange |
|
requestAudioFocus |
AUDIOFOCUS_GAIN_TRANSIENT
public static final int AUDIOFOCUS_GAIN_TRANSIENT = 2
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 | |
|---|---|
onAudioFocusChange |
|
requestAudioFocus |
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
public static final int AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE = 4
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.
| See also | |
|---|---|
requestAudioFocus |
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
public static final int AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK = 3
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 | |
|---|---|
onAudioFocusChange |
|
requestAudioFocus |
Public methods
abandonAudioFocusRequest
public static int abandonAudioFocusRequest(
@NonNull AudioManager audioManager,
@NonNull AudioFocusRequestCompat focusRequest
)
Abandon audio focus. Causes the previous focus owner, if any, to receive focus.
| Parameters | |
|---|---|
@NonNull AudioFocusRequestCompat focusRequest |
the |
| Returns | |
|---|---|
int |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if passed a null argument |
getStreamMaxVolume
public static @IntRange(from = 0) int getStreamMaxVolume(@NonNull AudioManager audioManager, int streamType)
Returns the maximum volume index for a particular stream.
| Parameters | |
|---|---|
int streamType |
The stream type whose maximum volume index is returned. |
| Returns | |
|---|---|
@IntRange(from = 0) int |
The maximum valid volume index for the stream. |
getStreamMinVolume
public static @IntRange(from = 0) int getStreamMinVolume(@NonNull AudioManager audioManager, int streamType)
Returns the minimum volume index for a particular stream.
| Parameters | |
|---|---|
int streamType |
The stream type whose minimum volume index is returned. |
| Returns | |
|---|---|
@IntRange(from = 0) int |
The minimum valid volume index for the stream. |
isVolumeFixed
public static boolean isVolumeFixed(@NonNull AudioManager audioManager)
Indicates if the device implements a fixed volume policy.
Some devices may not have volume control and may operate at a fixed volume, and may not enable muting or changing the volume of audio streams. This method will return true on such devices.
Compatibility: It returns false on API level below 21 even if the device has fixed volume.
requestAudioFocus
public static int requestAudioFocus(
@NonNull AudioManager audioManager,
@NonNull 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 | |
|---|---|
@NonNull AudioFocusRequestCompat focusRequest |
an |
| Returns | |
|---|---|
int |
| Throws | |
|---|---|
java.lang.NullPointerException |
if passed a null argument |