From 050dff6548abfb4c9c3d38c6daa6074ed1d4f985 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Tue, 18 Oct 2022 11:05:24 +0200 Subject: [PATCH] Voice Broadcast - Rename voice message files with sequence number --- .../features/voicebroadcast/VoiceBroadcastRecorder.kt | 3 ++- .../features/voicebroadcast/VoiceBroadcastRecorderQ.kt | 6 +++++- .../voicebroadcast/usecase/StartVoiceBroadcastUseCase.kt | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorder.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorder.kt index 2668501a8d..37ff920c57 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorder.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorder.kt @@ -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) } } diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorderQ.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorderQ.kt index 620db721c9..404b112574 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorderQ.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/VoiceBroadcastRecorderQ.kt @@ -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 } diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCase.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCase.kt index 2a306bcd28..780150d5e7 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCase.kt @@ -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,