mirror of
https://github.com/element-hq/element-android
synced 2024-10-06 16:22:18 +00:00
Catch race condition while recording voice audio (#7009)
This commit is contained in:
parent
b37996e4c3
commit
ae653eb672
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? {
|
fun stopRecording(): MultiPickerAudioType? {
|
||||||
tryOrNull("Cannot stop media recording amplitude") {
|
|
||||||
stopRecordingAmplitudes()
|
|
||||||
}
|
|
||||||
val voiceMessageFile = tryOrNull("Cannot stop media recorder!") {
|
val voiceMessageFile = tryOrNull("Cannot stop media recorder!") {
|
||||||
voiceRecorder.stopRecord()
|
voiceRecorder.stopRecord()
|
||||||
voiceRecorder.getVoiceMessageFile()
|
voiceRecorder.getVoiceMessageFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
tryOrNull("Cannot stop media recording amplitude") {
|
||||||
|
stopRecordingAmplitudes()
|
||||||
|
}
|
||||||
|
|
||||||
|
return try {
|
||||||
voiceMessageFile?.let {
|
voiceMessageFile?.let {
|
||||||
val outputFileUri = FileProvider.getUriForFile(context, buildMeta.applicationId + ".fileProvider", it, "Voice message.${it.extension}")
|
val outputFileUri = FileProvider.getUriForFile(context, buildMeta.applicationId + ".fileProvider", it, "Voice message.${it.extension}")
|
||||||
return outputFileUri
|
outputFileUri
|
||||||
.toMultiPickerAudioType(context)
|
.toMultiPickerAudioType(context)
|
||||||
?.apply {
|
?.apply {
|
||||||
waveform = if (amplitudeList.size < 50) {
|
waveform = if (amplitudeList.size < 50) {
|
||||||
|
@ -99,10 +100,13 @@ class AudioMessageHelper @Inject constructor(
|
||||||
amplitudeList.chunked(amplitudeList.size / 50) { items -> items.maxOrNull() ?: 0 }
|
amplitudeList.chunked(amplitudeList.size / 50) { items -> items.maxOrNull() ?: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: return null
|
}
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
Timber.e(e, "Cannot stop voice recording")
|
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() {
|
private fun handlePlayOrPauseRecordingPlayback() {
|
||||||
audioMessageHelper.startOrPauseRecordingPlayback()
|
try {
|
||||||
|
audioMessageHelper.startOrPauseRecordingPlayback()
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
_viewEvents.post(MessageComposerViewEvents.VoicePlaybackOrRecordingFailure(failure))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun endAllVoiceActions(deleteRecord: Boolean = true) {
|
fun endAllVoiceActions(deleteRecord: Boolean = true) {
|
||||||
|
|
Loading…
Reference in a new issue