when playing audio before connecting a room, play audio frozen for about a second
As the title, when we connect the room before, we played the music in advance. then call the connect room, the concert frozen for about a second.
need to use speaker for testing, since LiveKit defaults to earpiece, this will be very obvious.
the process of reproducing the problem is to use the speaker to play music in advance, and then connect the room to feel the problem.
eg:
//Suppose this is a code to play music
MediaPlayer.play();
//then we connect the rooms
room.connect(wsURL, token)
//use audioHandler.selectDevice to enable speaker
I feel like room.connect turned off the audio device during the connection process, and then suddenly turned it on again.
This is really a problem, my current solution is to use while to turn on the speaker before connect, but occasionally there are still problems.
val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
var timer = true
var timerClockTime = System.currentTimeMillis()
launch {
withContext(Dispatchers.IO) {
while (timer) {
if (System.currentTimeMillis() - timerClockTime > 3000) {
connected = true
timer = false
}
audioManager.isSpeakerphoneOn = true
audioManager.mode = AudioManager.MODE_NORMAL
}
}
}
launch {
room.connect(
wsURL,
token,
)
}
I suspect that there is an abnormality in the switching of audio during the connection process of LiveKit Android SDK.
Because even if the speaker is turned on before connect, it will be turned off when the code executes to connect until the connection is successful.
You can change the default priority of the audio devices by passing in an AudioSwitchHandler with the preferredDeviceList set to have Speakerphone prioritized over Earpiece.
@davidliu
still not working.
I have done the following configuration:
// Suppose this is a code to play music
MediaPlayer.play();
// eg:
var audioHandler = AudioSwitchHandler(application)
audioHandler.loggingEnabled = true
audioHandler.preferredDeviceList = listOf(
AudioDevice.Speakerphone::class.java,
AudioDevice.Earpiece::class.java,
AudioDevice.BluetoothHeadset::class.java,
AudioDevice.WiredHeadset::class.java,
)
var room = LiveKit.create(
applicationContext, overrides = LiveKitOverrides(
audioHandler = audioHandler
), options = options
)
// As long as the following connect is executed, the music will pause for 1-2s, and then continue
// If I remove the connect code, the playback will not be affected
room.connect(
wsURL,
token,
)
I think this might be an audio focus issue? Are you managing audio focus on your own? If that's the case, AudioSwitchHandler now has a manageAudioFocus flag to turn off the internal focus handling.
I'm not sure because after I updated to version 1.2.2, this problem disappeared.
I will observe it for a while before commenting.