davidliu
Committed by GitHub

Audio changes (#579)

* Explicitly expose AudioSwitchHandler

* Default prioritizing speaker over earpiece
---
"client-sdk-android": minor
---
Default prioritizing speaker over earpiece
... ...
---
"client-sdk-android": minor
---
Explicitly expose AudioSwitchHandler from Room for easier audio handling
... ...
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
... ... @@ -27,7 +27,8 @@ import javax.inject.Inject
import javax.inject.Singleton
/**
* An [AudioHandler] built on top of [AudioSwitch].
* An [AudioHandler] built on top of [AudioSwitch]. This handles things such as
* getting the audio focus as needed, as well as automatic audio output device management.
*
* The various settings should be set before connecting to a [Room] and [start] is called.
*/
... ... @@ -222,8 +223,8 @@ constructor(private val context: Context) : AudioHandler {
listOf(
AudioDevice.BluetoothHeadset::class.java,
AudioDevice.WiredHeadset::class.java,
AudioDevice.Earpiece::class.java,
AudioDevice.Speakerphone::class.java,
AudioDevice.Earpiece::class.java,
)
}
}
... ...
... ... @@ -26,10 +26,13 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import io.livekit.android.ConnectOptions
import io.livekit.android.LiveKit
import io.livekit.android.LiveKitOverrides
import io.livekit.android.RoomOptions
import io.livekit.android.Version
import io.livekit.android.audio.AudioHandler
import io.livekit.android.audio.AudioProcessingController
import io.livekit.android.audio.AudioSwitchHandler
import io.livekit.android.audio.AuthedAudioProcessingController
import io.livekit.android.audio.CommunicationWorkaround
import io.livekit.android.dagger.InjectionNames
... ... @@ -77,6 +80,17 @@ constructor(
private val defaultDispatcher: CoroutineDispatcher,
@Named(InjectionNames.DISPATCHER_IO)
private val ioDispatcher: CoroutineDispatcher,
/**
* The [AudioHandler] for setting up the audio as need.
*
* By default, this is an instance of [AudioSwitchHandler].
*
* This can be substituted for your own custom implementation through
* [LiveKitOverrides.audioOptions] when creating the room with [LiveKit.create].
*
* @see [audioSwitchHandler]
* @see [AudioSwitchHandler]
*/
val audioHandler: AudioHandler,
private val closeableManager: CloseableManager,
private val e2EEManagerFactory: E2EEManager.Factory,
... ... @@ -272,6 +286,14 @@ constructor(
val remoteParticipants: Map<Participant.Identity, RemoteParticipant>
get() = mutableRemoteParticipants
/**
* A convenience getter for the audio handler as a [AudioSwitchHandler].
*
* Will return null if [audioHandler] is not a [AudioSwitchHandler].
*/
val audioSwitchHandler: AudioSwitchHandler?
get() = audioHandler as? AudioSwitchHandler
private var sidToIdentity = mutableMapOf<Participant.Sid, Participant.Identity>()
private var mutableActiveSpeakers by flowDelegate(emptyList<Participant>())
... ...