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 package im.vector.app.features.voicebroadcast
import androidx.annotation.IntRange
import im.vector.app.features.voice.VoiceRecorder import im.vector.app.features.voice.VoiceRecorder
import java.io.File import java.io.File
@ -26,6 +27,6 @@ interface VoiceBroadcastRecorder : VoiceRecorder {
fun startRecord(roomId: String, chunkLength: Int) fun startRecord(roomId: String, chunkLength: Int)
fun interface Listener { 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 { ) : AbstractVoiceRecorderQ(context), VoiceBroadcastRecorder {
private var maxFileSize = 0L // zero or negative for no limit private var maxFileSize = 0L // zero or negative for no limit
private var currentSequence = 0
override var listener: VoiceBroadcastRecorder.Listener? = null override var listener: VoiceBroadcastRecorder.Listener? = null
@ -51,6 +52,7 @@ class VoiceBroadcastRecorderQ(
override fun startRecord(roomId: String, chunkLength: Int) { override fun startRecord(roomId: String, chunkLength: Int) {
maxFileSize = (chunkLength * audioEncodingBitRate / 8).toLong() maxFileSize = (chunkLength * audioEncodingBitRate / 8).toLong()
currentSequence = 1
startRecord(roomId) startRecord(roomId)
} }
@ -58,6 +60,7 @@ class VoiceBroadcastRecorderQ(
super.stopRecord() super.stopRecord()
notifyOutputFileCreated() notifyOutputFileCreated()
listener = null listener = null
currentSequence = 0
} }
override fun release() { override fun release() {
@ -71,11 +74,12 @@ class VoiceBroadcastRecorderQ(
private fun onNextOutputFileStarted() { private fun onNextOutputFileStarted() {
notifyOutputFileCreated() notifyOutputFileCreated()
currentSequence++
} }
private fun notifyOutputFileCreated() { private fun notifyOutputFileCreated() {
outputFile?.let { outputFile?.let {
listener?.onVoiceMessageCreated(it) listener?.onVoiceMessageCreated(it, currentSequence)
outputFile = nextOutputFile outputFile = nextOutputFile
nextOutputFile = null nextOutputFile = null
} }

View File

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