Skip to content

Commit

Permalink
Catch race condition while recording voice audio
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Sep 1, 2022
1 parent b632d95 commit 5ff7f22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/6989.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch race condition crash in voice recording
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}

Expand Down

0 comments on commit 5ff7f22

Please sign in to comment.