Voice Broadcast - Rename voice message files with sequence number

This commit is contained in:
Florian Renaud 2022-10-18 11:05:24 +02:00
parent 03ac0f1f03
commit 050dff6548
3 changed files with 12 additions and 6 deletions

View file

@ -16,6 +16,7 @@
package im.vector.app.features.voicebroadcast
import androidx.annotation.IntRange
import im.vector.app.features.voice.VoiceRecorder
import java.io.File
@ -26,6 +27,6 @@ interface VoiceBroadcastRecorder : VoiceRecorder {
fun startRecord(roomId: String, chunkLength: Int)
fun interface Listener {
fun onVoiceMessageCreated(file: File)
fun onVoiceMessageCreated(file: File, @IntRange(from = 1) sequence: Int)
}
}

View file

@ -29,6 +29,7 @@ class VoiceBroadcastRecorderQ(
) : AbstractVoiceRecorderQ(context), VoiceBroadcastRecorder {
private var maxFileSize = 0L // zero or negative for no limit
private var currentSequence = 0
override var listener: VoiceBroadcastRecorder.Listener? = null
@ -51,6 +52,7 @@ class VoiceBroadcastRecorderQ(
override fun startRecord(roomId: String, chunkLength: Int) {
maxFileSize = (chunkLength * audioEncodingBitRate / 8).toLong()
currentSequence = 1
startRecord(roomId)
}
@ -58,6 +60,7 @@ class VoiceBroadcastRecorderQ(
super.stopRecord()
notifyOutputFileCreated()
listener = null
currentSequence = 0
}
override fun release() {
@ -71,11 +74,12 @@ class VoiceBroadcastRecorderQ(
private fun onNextOutputFileStarted() {
notifyOutputFileCreated()
currentSequence++
}
private fun notifyOutputFileCreated() {
outputFile?.let {
listener?.onVoiceMessageCreated(it)
listener?.onVoiceMessageCreated(it, currentSequence)
outputFile = nextOutputFile
nextOutputFile = null
}

View file

@ -79,20 +79,21 @@ class StartVoiceBroadcastUseCase @Inject constructor(
}
private fun startRecording(room: Room, eventId: String, chunkLength: Int) {
voiceBroadcastRecorder?.listener = VoiceBroadcastRecorder.Listener { file ->
sendVoiceFile(room, file, eventId)
voiceBroadcastRecorder?.listener = VoiceBroadcastRecorder.Listener { file, sequence ->
sendVoiceFile(room, file, eventId, sequence)
}
voiceBroadcastRecorder?.startRecord(room.roomId, chunkLength)
}
private fun sendVoiceFile(room: Room, voiceMessageFile: File, referenceEventId: String) {
private fun sendVoiceFile(room: Room, voiceMessageFile: File, referenceEventId: String, sequence: Int) {
val outputFileUri = FileProvider.getUriForFile(
context,
buildMeta.applicationId + ".fileProvider",
voiceMessageFile,
"Voice message.${voiceMessageFile.extension}"
"Voice Broadcast Part ($sequence).${voiceMessageFile.extension}"
)
val audioType = outputFileUri.toMultiPickerAudioType(context) ?: return
// TODO put sequence in event content
room.sendService().sendMedia(
attachment = audioType.toContentAttachmentData(isVoiceMessage = true),
compressBeforeSending = false,