Fix voice record not playable if displayed before download terminated

This commit is contained in:
Sylvain Berfini 2024-09-29 14:34:42 +02:00
parent 31d92abcdf
commit f6d4f56bbc

View file

@ -209,6 +209,14 @@ class MessageModel @WorkerThread constructor(
if (!allFilesDownloaded) {
computeContentsList()
}
for (content in message.contents) {
if (content.isVoiceRecording) {
Log.i("$TAG File transfer done, updating voice record info")
computeVoiceRecordContent(content)
break
}
}
}
}
@ -390,16 +398,7 @@ class MessageModel @WorkerThread constructor(
} else if (content.isVoiceRecording) {
Log.d("$TAG Found voice recording content")
isVoiceRecord.postValue(true)
voiceRecordPath = content.filePath ?: ""
val duration = content.fileDuration
voiceRecordingDuration.postValue(duration)
val formattedDuration = SimpleDateFormat(
"mm:ss",
Locale.getDefault()
).format(duration) // duration is in ms
formattedVoiceRecordingDuration.postValue(formattedDuration)
computeVoiceRecordContent(content)
displayableContentFound = true
} else {
if (content.isFile) {
@ -952,4 +951,21 @@ class MessageModel @WorkerThread constructor(
}
}
}
@WorkerThread
private fun computeVoiceRecordContent(content: Content) {
voiceRecordPath = content.filePath ?: ""
val duration = content.fileDuration
voiceRecordingDuration.postValue(duration)
val formattedDuration = SimpleDateFormat(
"mm:ss",
Locale.getDefault()
).format(duration) // duration is in ms
formattedVoiceRecordingDuration.postValue(formattedDuration)
Log.i(
"$TAG Found voice record with path [$voiceRecordPath] and duration [$formattedDuration]"
)
}
}