-
Notifications
You must be signed in to change notification settings - Fork 910
Voice Broadcast - Improve live indicator icon rendering #7579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Florian14
merged 11 commits into
develop
from
feature/fre/voice_broadcast_live_indicator
Nov 15, 2022
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6ee1e86
Improve live indicator
5eb260e
Unregister listeners on recording tile
2d006f8
Bind listener to live playback flag
a3cd0ee
Fix fetch playlist task getting stopped event from other voice broadcast
73d62c9
Emit first event on voice broadcast event flow
44608f0
Improve logs
288fc35
Changelog
403fd92
improve boolean condition
b85fcf9
Remove debounce on player buttons
d9454af
Stay in live when moving playback position in the same chunk
3239ec5
replace negation "!" with ".not()"
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [Voice Broadcast] Improve the live indicator icon rendering in the timeline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,6 @@ import im.vector.app.features.voicebroadcast.listening.VoiceBroadcastPlayer.Stat | |
| import im.vector.app.features.voicebroadcast.listening.usecase.GetLiveVoiceBroadcastChunksUseCase | ||
| import im.vector.app.features.voicebroadcast.model.VoiceBroadcast | ||
| import im.vector.app.features.voicebroadcast.model.VoiceBroadcastEvent | ||
| import im.vector.app.features.voicebroadcast.sequence | ||
| import im.vector.app.features.voicebroadcast.usecase.GetVoiceBroadcastEventUseCase | ||
| import im.vector.lib.core.utils.timer.CountUpTimer | ||
| import kotlinx.coroutines.Job | ||
|
|
@@ -70,18 +69,27 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
| private var currentVoiceBroadcastEvent: VoiceBroadcastEvent? = null | ||
|
|
||
| override var currentVoiceBroadcast: VoiceBroadcast? = null | ||
| override var isLiveListening: Boolean = false | ||
| @MainThread | ||
| set(value) { | ||
| if (field != value) { | ||
| Timber.w("isLiveListening: $field -> $value") | ||
| field = value | ||
| onLiveListeningChanged(value) | ||
| } | ||
| } | ||
|
|
||
| override var playingState = State.IDLE | ||
| @MainThread | ||
| set(value) { | ||
| if (field != value) { | ||
| Timber.w("## VoiceBroadcastPlayer state: $field -> $value") | ||
| Timber.w("playingState: $field -> $value") | ||
| field = value | ||
| onPlayingStateChanged(value) | ||
| } | ||
| } | ||
|
|
||
| /** Map voiceBroadcastId to listeners.*/ | ||
| /** Map voiceBroadcastId to listeners. */ | ||
| private val listeners: MutableMap<String, CopyOnWriteArrayList<Listener>> = mutableMapOf() | ||
|
|
||
| override fun playOrResume(voiceBroadcast: VoiceBroadcast) { | ||
|
|
@@ -121,7 +129,8 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
| listeners[voiceBroadcast.voiceBroadcastId]?.add(listener) ?: run { | ||
| listeners[voiceBroadcast.voiceBroadcastId] = CopyOnWriteArrayList<Listener>().apply { add(listener) } | ||
| } | ||
| listener.onStateChanged(if (voiceBroadcast == currentVoiceBroadcast) playingState else State.IDLE) | ||
| listener.onPlayingStateChanged(if (voiceBroadcast == currentVoiceBroadcast) playingState else State.IDLE) | ||
| listener.onLiveModeChanged(if (voiceBroadcast == currentVoiceBroadcast) isLiveListening else false) | ||
| } | ||
|
|
||
| override fun removeListener(voiceBroadcast: VoiceBroadcast, listener: Listener) { | ||
|
|
@@ -142,7 +151,10 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
|
|
||
| private fun observeVoiceBroadcastLiveState(voiceBroadcast: VoiceBroadcast) { | ||
| voiceBroadcastStateObserver = getVoiceBroadcastEventUseCase.execute(voiceBroadcast) | ||
| .onEach { currentVoiceBroadcastEvent = it.getOrNull() } | ||
| .onEach { | ||
| currentVoiceBroadcastEvent = it.getOrNull() | ||
| updateLiveListeningMode() | ||
| } | ||
| .launchIn(sessionScope) | ||
| } | ||
|
|
||
|
|
@@ -190,7 +202,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
| else -> playlist.firstOrNull() | ||
| } | ||
| val content = playlistItem?.audioEvent?.content ?: run { Timber.w("## VoiceBroadcastPlayer: No content to play"); return } | ||
| val sequence = playlistItem.audioEvent.sequence ?: run { Timber.w("## VoiceBroadcastPlayer: playlist item has no sequence"); return } | ||
| val sequence = playlistItem.sequence ?: run { Timber.w("## VoiceBroadcastPlayer: playlist item has no sequence"); return } | ||
| val sequencePosition = position?.let { it - playlistItem.startTime } ?: 0 | ||
| sessionScope.launch { | ||
| try { | ||
|
|
@@ -241,6 +253,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
| playbackTracker.updatePausedAtPlaybackTime(voiceBroadcast.voiceBroadcastId, positionMillis, positionMillis.toFloat() / duration) | ||
| } | ||
| playingState == State.PLAYING || playingState == State.BUFFERING -> { | ||
| updateLiveListeningMode(positionMillis) | ||
| startPlayback(positionMillis) | ||
| } | ||
| playingState == State.IDLE || playingState == State.PAUSED -> { | ||
|
|
@@ -302,15 +315,53 @@ class VoiceBroadcastPlayerImpl @Inject constructor( | |
| } | ||
|
|
||
| private fun onPlayingStateChanged(playingState: State) { | ||
| // Notify state change to all the listeners attached to the current voice broadcast id | ||
| // Update live playback flag | ||
| updateLiveListeningMode() | ||
|
|
||
| currentVoiceBroadcast?.voiceBroadcastId?.let { voiceBroadcastId -> | ||
| // Start or stop playback ticker | ||
| when (playingState) { | ||
| State.PLAYING -> playbackTicker.startPlaybackTicker(voiceBroadcastId) | ||
| State.PAUSED, | ||
| State.BUFFERING, | ||
| State.IDLE -> playbackTicker.stopPlaybackTicker(voiceBroadcastId) | ||
| } | ||
| listeners[voiceBroadcastId]?.forEach { listener -> listener.onStateChanged(playingState) } | ||
| // Notify state change to all the listeners attached to the current voice broadcast id | ||
| listeners[voiceBroadcastId]?.forEach { listener -> listener.onPlayingStateChanged(playingState) } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Update the live listening state according to: | ||
| * - the voice broadcast state (started/paused/resumed/stopped), | ||
| * - the playing state (IDLE, PLAYING, PAUSED, BUFFERING), | ||
| * - the potential seek position (backward/forward). | ||
| */ | ||
| private fun updateLiveListeningMode(seekPosition: Int? = null) { | ||
| isLiveListening = when { | ||
| // the current voice broadcast is not live (ended) | ||
| !currentVoiceBroadcastEvent?.isLive.orFalse() -> false | ||
| // the player is stopped or paused | ||
| playingState == State.IDLE || playingState == State.PAUSED -> false | ||
| // the user has sought | ||
| seekPosition != null -> { | ||
| val seekDirection = seekPosition.compareTo(getCurrentPlaybackPosition() ?: 0) | ||
| when { | ||
| // backward | ||
| seekDirection < 0 -> false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's what caused one of the issues I mentioned. I guess it's a expected behaviour then. |
||
| // forward: check if new sequence is the last one | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| else -> playlist.findByPosition(seekPosition)?.sequence == playlist.lastOrNull()?.sequence | ||
| } | ||
| } | ||
| // otherwise, stay in live or go in live if we reached the last sequence | ||
| else -> isLiveListening || playlist.currentSequence == playlist.lastOrNull()?.sequence | ||
| } | ||
| } | ||
|
|
||
| private fun onLiveListeningChanged(isLiveListening: Boolean) { | ||
| currentVoiceBroadcast?.voiceBroadcastId?.let { voiceBroadcastId -> | ||
| // Notify live mode change to all the listeners attached to the current voice broadcast id | ||
| listeners[voiceBroadcastId]?.forEach { listener -> listener.onLiveModeChanged(isLiveListening) } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little nit pick here: I'd either use
.not()at the end or.isLive == false, the current version makes the starting!easy to miss.