Stay organized with collections
Save and categorize content based on your preferences.
OnAudioFocusChangeListener
interface OnAudioFocusChangeListener
Interface definition for a callback to be invoked when the audio focus of the system is updated.
Summary
Public methods |
abstract Unit |
Called on the listener to notify it the audio focus for this listener has been changed.
|
Public methods
onAudioFocusChange
abstract fun onAudioFocusChange(focusChange: Int): Unit
Called on the listener to notify it the audio focus for this listener has been changed. The focusChange value indicates whether the focus was gained, whether the focus was lost, and whether that loss is transient, or whether the new focus holder will hold it for an unknown amount of time. When losing focus, listeners can use the focus change information to decide what behavior to adopt when losing focus. A music player could for instance elect to lower the volume of its music stream (duck) for transient focus losses, and pause otherwise.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# AudioManager.OnAudioFocusChangeListener\n\nAdded in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnAudioFocusChangeListener\n==========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/AudioManager.OnAudioFocusChangeListener \"View this page in Java\") \n\n```\ninterface OnAudioFocusChangeListener\n```\n\n|------------------------------------------------------------|\n| [android.media.AudioManager.OnAudioFocusChangeListener](#) |\n\nInterface definition for a callback to be invoked when the audio focus of the system is updated.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onAudioFocusChange](#onAudioFocusChange(kotlin.Int))`(`focusChange:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called on the listener to notify it the audio focus for this listener has been changed. |\n\nPublic methods\n--------------\n\n### onAudioFocusChange\n\nAdded in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onAudioFocusChange(focusChange: Int): Unit\n```\n\nCalled on the listener to notify it the audio focus for this listener has been changed. The focusChange value indicates whether the focus was gained, whether the focus was lost, and whether that loss is transient, or whether the new focus holder will hold it for an unknown amount of time. When losing focus, listeners can use the focus change information to decide what behavior to adopt when losing focus. A music player could for instance elect to lower the volume of its music stream (duck) for transient focus losses, and pause otherwise.\n\n| Parameters ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `focusChange` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the type of focus change, one of [AudioManager.AUDIOFOCUS_GAIN](/reference/kotlin/android/media/AudioManager#AUDIOFOCUS_GAIN:kotlin.Int), [AudioManager.AUDIOFOCUS_LOSS](/reference/kotlin/android/media/AudioManager#AUDIOFOCUS_LOSS:kotlin.Int), [AudioManager.AUDIOFOCUS_LOSS_TRANSIENT](/reference/kotlin/android/media/AudioManager#AUDIOFOCUS_LOSS_TRANSIENT:kotlin.Int) and [AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK](/reference/kotlin/android/media/AudioManager#AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:kotlin.Int). |"]]