AudioManagerCompat


@UnstableApi
public final class AudioManagerCompat


Compatibility layer for AudioManager with fallbacks for older Android versions.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation AudioManagerCompat.AudioFocusGain

Audio focus gain types.

Constants

static final int

Used 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").

static final int

Used to indicate no audio focus has been gained or lost, or requested.

Public methods

static int
abandonAudioFocusRequest(
    AudioManager audioManager,
    AudioFocusRequestCompat focusRequest
)

Abandon audio focus.

static @IntRange(from = 0) int
getStreamMaxVolume(
    AudioManager audioManager,
    @C.StreamType int streamType
)

Returns the maximum volume index for a particular stream.

static @IntRange(from = 0) int
getStreamMinVolume(
    AudioManager audioManager,
    @C.StreamType int streamType
)

Returns the minimum volume index for a particular stream.

static int
requestAudioFocus(
    AudioManager audioManager,
    AudioFocusRequestCompat focusRequest
)

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.

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.

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.

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.

AUDIOFOCUS_NONE

public static final int AUDIOFOCUS_NONE = 0

Used to indicate no audio focus has been gained or lost, or requested.

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

The AudioManager.

AudioFocusRequestCompat focusRequest

The AudioFocusRequestCompat that was used when requesting focus with requestAudioFocus.

getStreamMaxVolume

public static @IntRange(from = 0) int getStreamMaxVolume(
    AudioManager audioManager,
    @C.StreamType int streamType
)

Returns the maximum volume index for a particular stream.

Parameters
AudioManager audioManager

The AudioManager.

@C.StreamType int streamType

The C.StreamType 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(
    AudioManager audioManager,
    @C.StreamType int streamType
)

Returns the minimum volume index for a particular stream.

Parameters
AudioManager audioManager

The AudioManager.

@C.StreamType int streamType

The C.StreamType whose minimum volume index is returned.

Returns
@IntRange(from = 0) 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

The AudioManager.

AudioFocusRequestCompat focusRequest

An AudioFocusRequestCompat instance used to configure how focus is requested.