Do not wait for state event feedback for pause/stop actions on the recorder

This commit is contained in:
Florian Renaud 2022-11-24 10:18:58 +01:00
parent 3ebcd8c1f4
commit 023326a20d
3 changed files with 14 additions and 2 deletions

View file

@ -97,6 +97,7 @@ class VoiceBroadcastRecorderQ(
} }
override fun pauseRecord() { override fun pauseRecord() {
if (recordingState != VoiceBroadcastRecorder.State.Recording) return
tryOrNull { mediaRecorder?.stop() } tryOrNull { mediaRecorder?.stop() }
mediaRecorder?.reset() mediaRecorder?.reset()
recordingState = VoiceBroadcastRecorder.State.Paused recordingState = VoiceBroadcastRecorder.State.Paused
@ -105,6 +106,7 @@ class VoiceBroadcastRecorderQ(
} }
override fun resumeRecord() { override fun resumeRecord() {
if (recordingState != VoiceBroadcastRecorder.State.Paused) return
currentSequence++ currentSequence++
currentVoiceBroadcast?.let { startRecord(it.roomId) } currentVoiceBroadcast?.let { startRecord(it.roomId) }
recordingState = VoiceBroadcastRecorder.State.Recording recordingState = VoiceBroadcastRecorder.State.Recording

View file

@ -53,6 +53,10 @@ class PauseVoiceBroadcastUseCase @Inject constructor(
private suspend fun pauseVoiceBroadcast(room: Room, reference: RelationDefaultContent?) { private suspend fun pauseVoiceBroadcast(room: Room, reference: RelationDefaultContent?) {
Timber.d("## PauseVoiceBroadcastUseCase: Send new voice broadcast info state event") Timber.d("## PauseVoiceBroadcastUseCase: Send new voice broadcast info state event")
// immediately pause the recording
pauseRecording()
room.stateService().sendStateEvent( room.stateService().sendStateEvent(
eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO, eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO,
stateKey = session.myUserId, stateKey = session.myUserId,
@ -63,4 +67,8 @@ class PauseVoiceBroadcastUseCase @Inject constructor(
).toContent(), ).toContent(),
) )
} }
private fun pauseRecording() {
voiceBroadcastRecorder?.pauseRecord()
}
} }

View file

@ -54,6 +54,10 @@ class StopVoiceBroadcastUseCase @Inject constructor(
private suspend fun stopVoiceBroadcast(room: Room, reference: RelationDefaultContent?) { private suspend fun stopVoiceBroadcast(room: Room, reference: RelationDefaultContent?) {
Timber.d("## StopVoiceBroadcastUseCase: Send new voice broadcast info state event") Timber.d("## StopVoiceBroadcastUseCase: Send new voice broadcast info state event")
// Immediately stop the recording
stopRecording()
room.stateService().sendStateEvent( room.stateService().sendStateEvent(
eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO, eventType = VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO,
stateKey = session.myUserId, stateKey = session.myUserId,
@ -63,8 +67,6 @@ class StopVoiceBroadcastUseCase @Inject constructor(
lastChunkSequence = voiceBroadcastRecorder?.currentSequence, lastChunkSequence = voiceBroadcastRecorder?.currentSequence,
).toContent(), ).toContent(),
) )
stopRecording()
} }
private fun stopRecording() { private fun stopRecording() {