diff --git a/changelog.d/8313.bugfix b/changelog.d/8313.bugfix new file mode 100644 index 0000000000..b524678101 --- /dev/null +++ b/changelog.d/8313.bugfix @@ -0,0 +1 @@ +Keep screen on while recording voicebroadcast diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/AudioMessageHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/AudioMessageHelper.kt index c55f8ec047..149f0fb0aa 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/AudioMessageHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/AudioMessageHelper.kt @@ -239,7 +239,7 @@ class AudioMessageHelper @Inject constructor( val percentage = currentPosition.toFloat() / totalDuration playbackTracker.updatePlayingAtPlaybackTime(id, currentPosition, percentage) } else { - playbackTracker.stopPlayback(id) + playbackTracker.stopPlaybackOrRecorder(id) stopPlaybackTicker() } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt index c598a99af7..00382b5a3f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt @@ -100,7 +100,7 @@ class AudioMessagePlaybackTracker @Inject constructor() { } } - fun stopPlayback(id: String) { + fun stopPlaybackOrRecorder(id: String) { val state = getPlaybackState(id) if (state !is Listener.State.Error) { setState(id, Listener.State.Idle) diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt index 5bb890b07c..5a91021089 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt @@ -527,7 +527,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( State.Idle -> { // restart the playback time if player completed with less than 1s remaining time if (percentage == null || (playlist.duration - position) < 1000) { - playbackTracker.stopPlayback(id) + playbackTracker.stopPlaybackOrRecorder(id) } else { playbackTracker.updatePausedAtPlaybackTime(id, position, percentage) } diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/recording/usecase/StartVoiceBroadcastUseCase.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/recording/usecase/StartVoiceBroadcastUseCase.kt index d807c67f74..3b0644f6d2 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/recording/usecase/StartVoiceBroadcastUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/recording/usecase/StartVoiceBroadcastUseCase.kt @@ -20,6 +20,7 @@ import android.content.Context import androidx.core.content.FileProvider import im.vector.app.core.resources.BuildMeta import im.vector.app.features.attachments.toContentAttachmentData +import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker import im.vector.app.features.session.coroutineScope import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants import im.vector.app.features.voicebroadcast.VoiceBroadcastFailure @@ -54,6 +55,7 @@ import javax.inject.Inject class StartVoiceBroadcastUseCase @Inject constructor( private val session: Session, private val voiceBroadcastRecorder: VoiceBroadcastRecorder?, + private val playbackTracker: AudioMessagePlaybackTracker, private val context: Context, private val buildMeta: BuildMeta, private val getRoomLiveVoiceBroadcastsUseCase: GetRoomLiveVoiceBroadcastsUseCase, @@ -106,10 +108,14 @@ class StartVoiceBroadcastUseCase @Inject constructor( } override fun onStateUpdated(state: VoiceBroadcastRecorder.State) { - if (state == VoiceBroadcastRecorder.State.Error) { - session.coroutineScope.launch { - pauseVoiceBroadcastUseCase.execute(room.roomId) + when (state) { + VoiceBroadcastRecorder.State.Recording -> playbackTracker.updateCurrentRecording(AudioMessagePlaybackTracker.RECORDING_ID, emptyList()) + VoiceBroadcastRecorder.State.Idle -> playbackTracker.stopPlaybackOrRecorder(AudioMessagePlaybackTracker.RECORDING_ID) + VoiceBroadcastRecorder.State.Error -> { + playbackTracker.stopPlaybackOrRecorder(AudioMessagePlaybackTracker.RECORDING_ID) + session.coroutineScope.launch { pauseVoiceBroadcastUseCase.execute(room.roomId) } } + else -> Unit } } }) diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/GetVoiceBroadcastStateEventLiveUseCase.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/GetVoiceBroadcastStateEventLiveUseCase.kt index 22fb0df6f9..a27b1689f7 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/GetVoiceBroadcastStateEventLiveUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/usecase/GetVoiceBroadcastStateEventLiveUseCase.kt @@ -47,8 +47,7 @@ class GetVoiceBroadcastStateEventLiveUseCase @Inject constructor( ) { fun execute(voiceBroadcast: VoiceBroadcast): Flow> { - val room = session.getRoom(voiceBroadcast.roomId) ?: error("Unknown roomId: ${voiceBroadcast.roomId}") - return getMostRecentVoiceBroadcastEventFlow(room, voiceBroadcast) + return getMostRecentVoiceBroadcastEventFlow(voiceBroadcast) .onEach { event -> Timber.d( "## VoiceBroadcast | " + @@ -61,7 +60,8 @@ class GetVoiceBroadcastStateEventLiveUseCase @Inject constructor( /** * Get a flow of the most recent event for the given voice broadcast. */ - private fun getMostRecentVoiceBroadcastEventFlow(room: Room, voiceBroadcast: VoiceBroadcast): Flow> { + private fun getMostRecentVoiceBroadcastEventFlow(voiceBroadcast: VoiceBroadcast): Flow> { + val room = session.getRoom(voiceBroadcast.roomId) ?: error("Unknown roomId: ${voiceBroadcast.roomId}") val startedEventFlow = room.flow().liveTimelineEvent(voiceBroadcast.voiceBroadcastId) // observe started event changes return startedEventFlow diff --git a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt index 9aa0ddf3b2..a9a49034fc 100644 --- a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt @@ -57,6 +57,7 @@ class StartVoiceBroadcastUseCaseTest { StartVoiceBroadcastUseCase( session = fakeSession, voiceBroadcastRecorder = fakeVoiceBroadcastRecorder, + playbackTracker = mockk(), context = FakeContext().instance, buildMeta = mockk(), getRoomLiveVoiceBroadcastsUseCase = fakeGetRoomLiveVoiceBroadcastsUseCase,