mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
add RecordVoiceMessage audio focus requester for recording
separates recording from playback focus - willPausedWhenDucked is false for recording so notification sounds don't interrupt mid-recording Signed-off-by: vmfunc <celeste@linux.com>
This commit is contained in:
+1
-1
@@ -249,7 +249,7 @@ class DefaultVoiceMessageComposerPresenter(
|
|||||||
|
|
||||||
private fun CoroutineScope.startRecording() = launch {
|
private fun CoroutineScope.startRecording() = launch {
|
||||||
try {
|
try {
|
||||||
audioFocus.requestAudioFocus(AudioFocusRequester.VoiceMessage) {}
|
audioFocus.requestAudioFocus(AudioFocusRequester.RecordVoiceMessage) {}
|
||||||
voiceRecorder.startRecord()
|
voiceRecorder.startRecord()
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
audioFocus.releaseAudioFocus()
|
audioFocus.releaseAudioFocus()
|
||||||
|
|||||||
+1
@@ -11,6 +11,7 @@ package io.element.android.libraries.audio.api
|
|||||||
enum class AudioFocusRequester {
|
enum class AudioFocusRequester {
|
||||||
ElementCall,
|
ElementCall,
|
||||||
VoiceMessage,
|
VoiceMessage,
|
||||||
|
RecordVoiceMessage,
|
||||||
MediaViewer,
|
MediaViewer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -81,7 +81,8 @@ class DefaultAudioFocus(
|
|||||||
private fun AudioFocusRequester.toAudioUsage(): Int {
|
private fun AudioFocusRequester.toAudioUsage(): Int {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
AudioFocusRequester.ElementCall,
|
AudioFocusRequester.ElementCall,
|
||||||
AudioFocusRequester.VoiceMessage -> AudioAttributes.USAGE_VOICE_COMMUNICATION
|
AudioFocusRequester.VoiceMessage,
|
||||||
|
AudioFocusRequester.RecordVoiceMessage -> AudioAttributes.USAGE_VOICE_COMMUNICATION
|
||||||
AudioFocusRequester.MediaViewer -> AudioAttributes.USAGE_MEDIA
|
AudioFocusRequester.MediaViewer -> AudioAttributes.USAGE_MEDIA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,8 @@ private fun AudioFocusRequester.toAudioUsage(): Int {
|
|||||||
private fun AudioFocusRequester.toAudioStream(): Int {
|
private fun AudioFocusRequester.toAudioStream(): Int {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
AudioFocusRequester.ElementCall,
|
AudioFocusRequester.ElementCall,
|
||||||
AudioFocusRequester.VoiceMessage -> AudioManager.STREAM_VOICE_CALL
|
AudioFocusRequester.VoiceMessage,
|
||||||
|
AudioFocusRequester.RecordVoiceMessage -> AudioManager.STREAM_VOICE_CALL
|
||||||
AudioFocusRequester.MediaViewer -> AudioManager.STREAM_MUSIC
|
AudioFocusRequester.MediaViewer -> AudioManager.STREAM_MUSIC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +101,9 @@ private fun AudioFocusRequester.willPausedWhenDucked(): Boolean {
|
|||||||
// (note that for Element Call, there is no action when the focus is lost)
|
// (note that for Element Call, there is no action when the focus is lost)
|
||||||
AudioFocusRequester.ElementCall,
|
AudioFocusRequester.ElementCall,
|
||||||
AudioFocusRequester.VoiceMessage -> true
|
AudioFocusRequester.VoiceMessage -> true
|
||||||
|
// no audio output to duck when recording, and we don't want notification
|
||||||
|
// sounds to interrupt a recording via transient focus loss
|
||||||
|
AudioFocusRequester.RecordVoiceMessage -> false
|
||||||
// For the MediaViewer, we let the system automatically handle the ducking
|
// For the MediaViewer, we let the system automatically handle the ducking
|
||||||
// https://developer.android.com/media/optimize/audio-focus#automatic-ducking
|
// https://developer.android.com/media/optimize/audio-focus#automatic-ducking
|
||||||
AudioFocusRequester.MediaViewer -> false
|
AudioFocusRequester.MediaViewer -> false
|
||||||
|
|||||||
Reference in New Issue
Block a user