AudioManagerCompat

class AudioManagerCompat
kotlin.Any
   ↳ androidx.media.AudioManagerCompat

Compatibility library for AudioManager with fallbacks for older platforms.

Summary

Constants

static Int

Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.

static Int

Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time.

static 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 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(@NonNull audioManager: AudioManager, @NonNull focusRequest: AudioFocusRequestCompat)

Abandon audio focus.

static Int
requestAudioFocus(@NonNull audioManager: AudioManager, @NonNull focusRequest: AudioFocusRequestCompat)

Requests audio focus.

Constants

AUDIOFOCUS_GAIN

static val AUDIOFOCUS_GAIN: Int

Used to indicate a gain of audio focus, or a request of audio focus, of unknown duration.

Value: AudioManager.AUDIOFOCUS_GAIN

AUDIOFOCUS_GAIN_TRANSIENT

static val AUDIOFOCUS_GAIN_TRANSIENT: 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.

Value: AudioManager.AUDIOFOCUS_GAIN_TRANSIENT

AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

static val AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE: 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.

Value: AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE

AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

static val AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK: 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.

Value: AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK

Public methods

abandonAudioFocusRequest

static fun abandonAudioFocusRequest(@NonNull audioManager: AudioManager, @NonNull focusRequest: AudioFocusRequestCompat): Int

Abandon audio focus. Causes the previous focus owner, if any, to receive focus.

Parameters
focusRequest AudioManager: the AudioFocusRequestCompat that was used when requesting focus with requestAudioFocus(AudioManager, AudioFocusRequestCompat).
Return
Int: AudioManager#AUDIOFOCUS_REQUEST_FAILED or
Exceptions
IllegalArgumentException if passed a null argument

requestAudioFocus

static fun requestAudioFocus(@NonNull audioManager: AudioManager, @NonNull 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
focusRequest AudioManager: an AudioFocusRequestCompat instance used to configure how focus is requested.
Return
Int: AudioManager#AUDIOFOCUS_REQUEST_FAILED or .
Exceptions
NullPointerException if passed a null argument