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 79d59064e9..f04b85859b 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 @@ -145,19 +145,25 @@ class VoiceBroadcastPlayerImpl @Inject constructor( playingState = State.BUFFERING - observeVoiceBroadcastLiveState(voiceBroadcast) + observeVoiceBroadcastStateEvent(voiceBroadcast) fetchPlaylistAndStartPlayback(voiceBroadcast) } - private fun observeVoiceBroadcastLiveState(voiceBroadcast: VoiceBroadcast) { + private fun observeVoiceBroadcastStateEvent(voiceBroadcast: VoiceBroadcast) { voiceBroadcastStateObserver = getVoiceBroadcastEventUseCase.execute(voiceBroadcast) - .onEach { - currentVoiceBroadcastEvent = it.getOrNull() - updateLiveListeningMode() - } + .onEach { onVoiceBroadcastStateEventUpdated(it.getOrNull()) } .launchIn(sessionScope) } + private fun onVoiceBroadcastStateEventUpdated(event: VoiceBroadcastEvent?) { + if (event == null) { + stop() + } else { + currentVoiceBroadcastEvent = event + updateLiveListeningMode() + } + } + private fun fetchPlaylistAndStartPlayback(voiceBroadcast: VoiceBroadcast) { fetchPlaylistTask = getLiveVoiceBroadcastChunksUseCase.execute(voiceBroadcast) .onEach {