InterruptionPolicy

data class InterruptionPolicy(val pauseOnLoss: Boolean = true, val duckOnTransient: Boolean = true, val duckVolume: Float = 0.2f, val resumeAfterTransient: Boolean = true, val pauseWhenBecomingNoisy: Boolean = true, val focus: AudioFocusKind = AudioFocusKind.Permanent)

What to do when something takes the right to make sound away.

A call arrives, another app starts playing, the headphones come out. Each platform reports these differently and each one expects a player to react. This is the one set of choices behind all of them; the platform guard maps its own signals onto InterruptionEvent and follows what is here.

Constructors

Link copied to clipboard
constructor(pauseOnLoss: Boolean = true, duckOnTransient: Boolean = true, duckVolume: Float = 0.2f, resumeAfterTransient: Boolean = true, pauseWhenBecomingNoisy: Boolean = true, focus: AudioFocusKind = AudioFocusKind.Permanent)

Properties

Link copied to clipboard

On a short loss that allows quiet playback, duck by duckVolume instead of pausing.

Link copied to clipboard

The share of the listener's volume that plays while ducked: 0.2 plays at a fifth of it. A duck only ever lowers the sound, and the listener's own volume setting is left alone.

Link copied to clipboard

The kind of audio focus to ask for (#451): AudioFocusKind.Permanent for music and films, or a transient kind for a short sound, such as a voice message or a notification, so the music it interrupts resumes after it. Android reads it; the other platforms have no such request and ignore it.

Link copied to clipboard

Pause when the sound is gone for good, for example another app took over playback.

Link copied to clipboard

Pause when the route stops being audible: wired headphones out, Bluetooth gone.

Link copied to clipboard

Play again after a short loss ends, but only when this policy was the one that paused.