Route voice/call recordings to headset instead of speaker, if possible

This commit is contained in:
Sylvain Berfini 2022-02-04 10:48:59 +01:00
parent 0232ae5be2
commit 0580dfa58f
4 changed files with 19 additions and 8 deletions

View file

@ -43,6 +43,7 @@ Group changes to describe their impact on the project, as follows:
### Fixed
- Chat notifications disappearing when app restarts
- "Infinite backstack", now each view is stored (at most) once in the backstack
- Voice messages / call recordings will be played on headset/headphones instead of speaker, if possible
- Going back to the dialer when pressing back in a chat room after clicking on a chat message notification
- Missing international prefix / phone number in assistant after granting permission
- Display issue for incoming call notification preventing to use answer/hangup actions on some Xiaomi devices (like Redmi Note 9S)

View file

@ -306,8 +306,9 @@ class ChatMessageContentData(
private fun initVoiceRecordPlayer() {
Log.i("[Voice Recording] Creating player for voice record")
// Use speaker sound card to play recordings, otherwise use earpiece
// In case no headphones/headset is connected, use speaker sound card to play recordings, otherwise use earpiece
// If none are available, default one will be used
var headphonesCard: String? = null
var speakerCard: String? = null
var earpieceCard: String? = null
for (device in coreContext.core.audioDevices) {
@ -316,12 +317,14 @@ class ChatMessageContentData(
speakerCard = device.id
} else if (device.type == AudioDevice.Type.Earpiece) {
earpieceCard = device.id
} else if (device.type == AudioDevice.Type.Headphones || device.type == AudioDevice.Type.Headset) {
headphonesCard = device.id
}
}
}
Log.i("[Voice Recording] Found speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
Log.i("[Voice Recording] Found headset/headphones sound card [$headphonesCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
val localPlayer = coreContext.core.createLocalPlayer(headphonesCard ?: speakerCard ?: earpieceCard, null, null)
if (localPlayer != null) {
voiceRecordingPlayer = localPlayer
} else {

View file

@ -428,8 +428,9 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
private fun initVoiceRecordPlayer() {
Log.i("[Chat Message Sending] Creating player for voice record")
// Use speaker sound card to play recordings, otherwise use earpiece
// In case no headphones/headset is connected, use speaker sound card to play recordings, otherwise use earpiece
// If none are available, default one will be used
var headphonesCard: String? = null
var speakerCard: String? = null
var earpieceCard: String? = null
for (device in coreContext.core.audioDevices) {
@ -438,12 +439,14 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
speakerCard = device.id
} else if (device.type == AudioDevice.Type.Earpiece) {
earpieceCard = device.id
} else if (device.type == AudioDevice.Type.Headphones || device.type == AudioDevice.Type.Headset) {
headphonesCard = device.id
}
}
}
Log.i("[Chat Message Sending] Found speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
Log.i("[Chat Message Sending] Found headset/headphones sound card [$headphonesCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
val localPlayer = coreContext.core.createLocalPlayer(headphonesCard ?: speakerCard ?: earpieceCard, null, null)
if (localPlayer != null) {
voiceRecordingPlayer = localPlayer
} else {

View file

@ -164,8 +164,9 @@ class RecordingData(val path: String, private val recordingListener: RecordingLi
}
private fun initPlayer() {
// Use speaker sound card to play recordings, otherwise use earpiece
// In case no headphones/headset is connected, use speaker sound card to play recordings, otherwise use earpiece
// If none are available, default one will be used
var headphonesCard: String? = null
var speakerCard: String? = null
var earpieceCard: String? = null
for (device in coreContext.core.audioDevices) {
@ -174,11 +175,14 @@ class RecordingData(val path: String, private val recordingListener: RecordingLi
speakerCard = device.id
} else if (device.type == AudioDevice.Type.Earpiece) {
earpieceCard = device.id
} else if (device.type == AudioDevice.Type.Headphones || device.type == AudioDevice.Type.Headset) {
headphonesCard = device.id
}
}
}
Log.i("[Recording VM] Found headset/headphones sound card [$headphonesCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
val localPlayer = coreContext.core.createLocalPlayer(headphonesCard ?: speakerCard ?: earpieceCard, null, null)
if (localPlayer != null) player = localPlayer
else Log.e("[Recording VM] Couldn't create local player!")
player.addListener(listener)