Improve logs

This commit is contained in:
Florian Renaud 2022-11-14 10:24:22 +01:00
parent 73d62c944c
commit 44608f080c
1 changed files with 15 additions and 6 deletions

View File

@ -70,12 +70,20 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
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)
}
@ -325,9 +333,9 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
/**
* Update the live listening state according to:
* - the voice broadcast state,
* - the playing state,
* - the potential seek position.
* - 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 {
@ -348,11 +356,12 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
// 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) }
}
}