AudioFocusManager
@UnstableApi
class AudioFocusManager
Manages requesting and responding to changes in audio focus.
This class should be used on a single background thread to avoid blocking system calls. The constructor can be called on any thread, but has to specify the Looper for the background thread used for accessing the class.
Summary
Nested types |
|---|
@DocumentedPlayer commands. |
interface AudioFocusManager.PlayerControlInterface to allow AudioFocusManager to give commands to a player. |
Constants |
|
|---|---|
const Int |
Do not play, because audio focus is lost or denied. |
const Int |
Play freely, because audio focus is granted or not applicable. |
const Int |
Do not play now, because of a transient focus loss. |
Public constructors |
|---|
AudioFocusManager(Constructs an AudioFocusManager to automatically handle audio focus for a player. |
Public functions |
|
|---|---|
Unit |
release()Called when the manager is no longer required. |
Unit |
setAudioAttributes(audioAttributes: AudioAttributes?)Sets audio attributes that should be used to manage audio focus. |
Int |
@AudioFocusManager.PlayerCommandCalled by the player to abandon or request audio focus based on the desired player state. |
Public properties |
|
|---|---|
Float |
Constants
PLAYER_COMMAND_DO_NOT_PLAY
const val PLAYER_COMMAND_DO_NOT_PLAY = -1: Int
Do not play, because audio focus is lost or denied.
PLAYER_COMMAND_PLAY_WHEN_READY
const val PLAYER_COMMAND_PLAY_WHEN_READY = 1: Int
Play freely, because audio focus is granted or not applicable.
PLAYER_COMMAND_WAIT_FOR_CALLBACK
const val PLAYER_COMMAND_WAIT_FOR_CALLBACK = 0: Int
Do not play now, because of a transient focus loss.
Public constructors
AudioFocusManager
AudioFocusManager(
context: Context!,
eventLooper: Looper!,
playerControl: AudioFocusManager.PlayerControl!
)
Constructs an AudioFocusManager to automatically handle audio focus for a player.
| Parameters | |
|---|---|
context: Context! |
The current context. |
eventLooper: Looper! |
A |
playerControl: AudioFocusManager.PlayerControl! |
A |
Public functions
release
fun release(): Unit
Called when the manager is no longer required. Audio focus will be released without making any calls to the PlayerControl.
setAudioAttributes
fun setAudioAttributes(audioAttributes: AudioAttributes?): Unit
Sets audio attributes that should be used to manage audio focus.
Call updateAudioFocus to update the audio focus based on these attributes.
| Parameters | |
|---|---|
audioAttributes: AudioAttributes? |
The audio attributes or |
updateAudioFocus
@AudioFocusManager.PlayerCommand
fun updateAudioFocus(playWhenReady: Boolean, @Player.State playbackState: Int): Int
Called by the player to abandon or request audio focus based on the desired player state.
| Parameters | |
|---|---|
playWhenReady: Boolean |
The desired value of playWhenReady. |
@Player.State playbackState: Int |
The desired playback state. |
| Returns | |
|---|---|
Int |
A |