mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 20:29:10 +03:00
Catch race condition while recording voice audio (#7009)
This commit is contained in:
parent
b37996e4c3
commit
ae653eb672
3 changed files with 17 additions and 8 deletions
1
changelog.d/6989.bugfix
Normal file
1
changelog.d/6989.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Catch race condition crash in voice recording
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue