AudioSessionManager

actual class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

actual class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

expect class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

actual class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

actual class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

actual class AudioSessionManager

Manages the platform audio session, controlling how the app interacts with the system audio infrastructure and other audio apps.

On Apple platforms, this wraps AVAudioSession and must be configured before opening audio streams. On Android, call bind(context) then setActive to request audio focus; interruptions are reported via observeInterruptions.

Example usage:

val sessionManager = AudioSessionManager()

// Configure for simultaneous recording and playback
sessionManager.configure(
category = AudioSessionCategory.PLAY_AND_RECORD,
mode = AudioSessionMode.MEASUREMENT,
)

// Activate the session before opening streams
sessionManager.setActive(true)

// Listen for route changes (e.g., headphones plugged in/out)
sessionManager.observeRouteChanges { info ->
println("Audio route changed: ${info.reason}")
}

// Deactivate when audio is no longer needed
sessionManager.setActive(false)

See also

Constructors

Link copied to clipboard
actual constructor()
actual constructor()
expect constructor()
actual constructor()
actual constructor()
actual constructor()

Functions

Link copied to clipboard
actual fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

actual fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

expect fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

actual fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

actual fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

actual fun attach(stream: AudioStream)

Pause and resume this stream automatically on interruptions. Does not start playback by itself. Does not close the stream.

Link copied to clipboard
fun bind(context: Context)

Provide an Android Context so setActive can request audio focus and so input AudioEngine.openStream can throw PermissionException when android.Manifest.permission.RECORD_AUDIO is missing. Uses Context.getApplicationContext.

Link copied to clipboard
actual fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

actual fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

expect fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

actual fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

actual fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

actual fun clearInterruptions(listener: (AudioInterruptionInfo) -> Unit)

Stop delivering interruptions to listener.

Link copied to clipboard
actual fun clearRouteChanges()

Stop listening for route changes.

actual fun clearRouteChanges()

Stop listening for route changes.

expect fun clearRouteChanges()

Stop listening for route changes.

actual fun clearRouteChanges()

Stop listening for route changes.

actual fun clearRouteChanges()

Stop listening for route changes.

actual fun clearRouteChanges()

Stop listening for route changes.

Link copied to clipboard
actual fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

actual fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

expect fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

actual fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

actual fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

actual fun configure(category: AudioSessionCategory, mode: AudioSessionMode)

Configure the audio session category and mode.

Link copied to clipboard
actual fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

actual fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

expect fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

actual fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

actual fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

actual fun detach(stream: AudioStream)

Stop auto-handling stream. No-op if it was not attached.

Link copied to clipboard

Whether microphone permission is currently granted.

Whether microphone permission is currently granted.

Whether microphone permission is currently granted.

Whether microphone permission is currently granted.

Whether microphone permission is currently granted.

Whether microphone permission is currently granted.

Link copied to clipboard

Register a listener for audio interruptions (phone calls, focus loss).

Register a listener for audio interruptions (phone calls, focus loss).

Register a listener for audio interruptions (phone calls, focus loss).

Register a listener for audio interruptions (phone calls, focus loss).

Register a listener for audio interruptions (phone calls, focus loss).

Register a listener for audio interruptions (phone calls, focus loss).

Link copied to clipboard
actual fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

actual fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

expect fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

actual fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

actual fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

actual fun observeRouteChanges(listener: (AudioRouteChangeInfo) -> Unit)

Register a listener for audio route change events.

Link copied to clipboard
actual fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

actual fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

expect fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

actual fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

actual fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

actual fun requestRecordPermission(onResult: (granted: Boolean) -> Unit)

Ask the system for microphone permission.

Link copied to clipboard
actual fun setActive(active: Boolean)

Activate or deactivate the audio session.

actual fun setActive(active: Boolean)

Activate or deactivate the audio session.

expect fun setActive(active: Boolean)

Activate or deactivate the audio session.

actual fun setActive(active: Boolean)

Activate or deactivate the audio session.

actual fun setActive(active: Boolean)

Activate or deactivate the audio session.

actual fun setActive(active: Boolean)

Activate or deactivate the audio session.