android: fix crash when playing recorded voice message (#3325)

* android: fix crash when playing recorded voice message

* better
This commit is contained in:
Stanislav Dmitrenko 2023-11-11 00:09:19 +08:00 committed by GitHub
parent 8d891005d9
commit e7d6ed66da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -284,9 +284,11 @@ actual object AudioPlayer: AudioPlayerInterface {
kotlin.runCatching { kotlin.runCatching {
helperPlayer.setDataSource(unencryptedFilePath) helperPlayer.setDataSource(unencryptedFilePath)
helperPlayer.prepare() helperPlayer.prepare()
helperPlayer.start() if (helperPlayer.duration <= 0) {
helperPlayer.stop() Log.e(TAG, "Duration of audio is incorrect: ${helperPlayer.duration}")
} else {
res = helperPlayer.duration res = helperPlayer.duration
}
helperPlayer.reset() helperPlayer.reset()
} }
return res return res

View File

@ -776,7 +776,11 @@ fun ComposeView(
.collect { .collect {
when(it) { when(it) {
is RecordingState.Started -> onAudioAdded(it.filePath, it.progressMs, false) is RecordingState.Started -> onAudioAdded(it.filePath, it.progressMs, false)
is RecordingState.Finished -> onAudioAdded(it.filePath, it.durationMs, true) is RecordingState.Finished -> if (it.durationMs > 300) {
onAudioAdded(it.filePath, it.durationMs, true)
} else {
cancelVoice()
}
is RecordingState.NotStarted -> {} is RecordingState.NotStarted -> {}
} }
} }