Compute file size from chunk length
This commit is contained in:
parent
fb9c747a20
commit
64e6a2bfab
@ -20,4 +20,7 @@ object VoiceBroadcastConstants {
|
|||||||
|
|
||||||
/** Voice Broadcast State Event. */
|
/** Voice Broadcast State Event. */
|
||||||
const val STATE_ROOM_VOICE_BROADCAST_INFO = "io.element.voice_broadcast_info"
|
const val STATE_ROOM_VOICE_BROADCAST_INFO = "io.element.voice_broadcast_info"
|
||||||
|
|
||||||
|
/** Default voice broadcast chunk duration, in seconds */
|
||||||
|
const val DEFAULT_CHUNK_LENGTH = 5
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ interface VoiceBroadcastRecorder : VoiceRecorder {
|
|||||||
|
|
||||||
var listener: Listener?
|
var listener: Listener?
|
||||||
|
|
||||||
|
fun startRecord(roomId: String, chunkLength: Int)
|
||||||
|
|
||||||
fun interface Listener {
|
fun interface Listener {
|
||||||
fun onVoiceMessageCreated(file: File)
|
fun onVoiceMessageCreated(file: File)
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class VoiceBroadcastRecorderQ(
|
|||||||
context: Context,
|
context: Context,
|
||||||
) : AbstractVoiceRecorderQ(context), VoiceBroadcastRecorder {
|
) : AbstractVoiceRecorderQ(context), VoiceBroadcastRecorder {
|
||||||
|
|
||||||
private val maxFileSize = 25_000L // 0,025 Mb = 25 Kb ~= 6s
|
private var maxFileSize = 25_000L // 0,025 Mb = 25 Kb ~= 6s
|
||||||
|
|
||||||
override var listener: VoiceBroadcastRecorder.Listener? = null
|
override var listener: VoiceBroadcastRecorder.Listener? = null
|
||||||
|
|
||||||
@ -49,6 +49,11 @@ class VoiceBroadcastRecorderQ(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun startRecord(roomId: String, chunkLength: Int) {
|
||||||
|
maxFileSize = (chunkLength * 0.004166).toLong() // TODO change this approximate conversion
|
||||||
|
startRecord(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun stopRecord() {
|
override fun stopRecord() {
|
||||||
super.stopRecord()
|
super.stopRecord()
|
||||||
notifyOutputFileCreated()
|
notifyOutputFileCreated()
|
||||||
|
@ -41,7 +41,7 @@ data class MessageVoiceBroadcastInfoContent(
|
|||||||
/** The [VoiceBroadcastState] value. **/
|
/** The [VoiceBroadcastState] value. **/
|
||||||
@Json(name = "state") val voiceBroadcastStateStr: String = "",
|
@Json(name = "state") val voiceBroadcastStateStr: String = "",
|
||||||
/** The length of the voice chunks in seconds. **/
|
/** The length of the voice chunks in seconds. **/
|
||||||
@Json(name = "chunk_length") val chunkLength: Long? = null,
|
@Json(name = "chunk_length") val chunkLength: Int? = null,
|
||||||
) : MessageContent {
|
) : MessageContent {
|
||||||
|
|
||||||
val voiceBroadcastState: VoiceBroadcastState? = VoiceBroadcastState.values()
|
val voiceBroadcastState: VoiceBroadcastState? = VoiceBroadcastState.values()
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package im.vector.app.features.voicebroadcast.usecase
|
package im.vector.app.features.voicebroadcast.usecase
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import im.vector.app.core.resources.BuildMeta
|
import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.features.attachments.toContentAttachmentData
|
import im.vector.app.features.attachments.toContentAttachmentData
|
||||||
@ -66,25 +65,24 @@ class StartVoiceBroadcastUseCase @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun startVoiceBroadcast(room: Room) {
|
private suspend fun startVoiceBroadcast(room: Room) {
|
||||||
Timber.d("## StartVoiceBroadcastUseCase: Send new voice broadcast info state event")
|
Timber.d("## StartVoiceBroadcastUseCase: Send new voice broadcast info state event")
|
||||||
|
val chunkLength = VoiceBroadcastConstants.DEFAULT_CHUNK_LENGTH // Todo Get the length from the room settings
|
||||||
val eventId = room.stateService().sendStateEvent(
|
val eventId = room.stateService().sendStateEvent(
|
||||||
eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO,
|
eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO,
|
||||||
stateKey = session.myUserId,
|
stateKey = session.myUserId,
|
||||||
body = MessageVoiceBroadcastInfoContent(
|
body = MessageVoiceBroadcastInfoContent(
|
||||||
voiceBroadcastStateStr = VoiceBroadcastState.STARTED.value,
|
voiceBroadcastStateStr = VoiceBroadcastState.STARTED.value,
|
||||||
chunkLength = 5L, // TODO Get length from voice broadcast settings
|
chunkLength = chunkLength,
|
||||||
).toContent()
|
).toContent()
|
||||||
)
|
)
|
||||||
|
|
||||||
startRecording(room, eventId)
|
startRecording(room, eventId, chunkLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startRecording(room: Room, eventId: String) {
|
private fun startRecording(room: Room, eventId: String, chunkLength: Int) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
voiceBroadcastRecorder?.listener = VoiceBroadcastRecorder.Listener { file ->
|
voiceBroadcastRecorder?.listener = VoiceBroadcastRecorder.Listener { file ->
|
||||||
sendVoiceFile(room, file, eventId)
|
sendVoiceFile(room, file, eventId)
|
||||||
}
|
}
|
||||||
voiceBroadcastRecorder?.startRecord(room.roomId)
|
voiceBroadcastRecorder?.startRecord(room.roomId, chunkLength)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendVoiceFile(room: Room, voiceMessageFile: File, referenceEventId: String) {
|
private fun sendVoiceFile(room: Room, voiceMessageFile: File, referenceEventId: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user