Catch race condition while recording voice audio (#7009)

This commit is contained in:
Jorge Martin Espinosa 2022-09-05 17:57:16 +02:00 committed by GitHub
parent b37996e4c3
commit ae653eb672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

1
changelog.d/6989.bugfix Normal file
View File

@ -0,0 +1 @@
Catch race condition crash in voice recording

View File

@ -79,18 +79,19 @@ class AudioMessageHelper @Inject constructor(
}
fun stopRecording(): MultiPickerAudioType? {
tryOrNull("Cannot stop media recording amplitude") {
stopRecordingAmplitudes()
}
val voiceMessageFile = tryOrNull("Cannot stop media recorder!") {
voiceRecorder.stopRecord()
voiceRecorder.getVoiceMessageFile()
}
try {
tryOrNull("Cannot stop media recording amplitude") {
stopRecordingAmplitudes()
}
return try {
voiceMessageFile?.let {
val outputFileUri = FileProvider.getUriForFile(context, buildMeta.applicationId + ".fileProvider", it, "Voice message.${it.extension}")
return outputFileUri
outputFileUri
.toMultiPickerAudioType(context)
?.apply {
waveform = if (amplitudeList.size < 50) {
@ -99,10 +100,13 @@ class AudioMessageHelper @Inject constructor(
amplitudeList.chunked(amplitudeList.size / 50) { items -> items.maxOrNull() ?: 0 }
}
}
} ?: return null
}
} catch (e: FileNotFoundException) {
Timber.e(e, "Cannot stop voice recording")
return null
null
} catch (e: RuntimeException) {
Timber.e(e, "Error while retrieving metadata")
null
}
}

View File

@ -883,7 +883,11 @@ class MessageComposerViewModel @AssistedInject constructor(
}
private fun handlePlayOrPauseRecordingPlayback() {
audioMessageHelper.startOrPauseRecordingPlayback()
try {
audioMessageHelper.startOrPauseRecordingPlayback()
} catch (failure: Throwable) {
_viewEvents.post(MessageComposerViewEvents.VoicePlaybackOrRecordingFailure(failure))
}
}
fun endAllVoiceActions(deleteRecord: Boolean = true) {