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,18 +70,26 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
override var currentVoiceBroadcast: VoiceBroadcast? = null override var currentVoiceBroadcast: VoiceBroadcast? = null
override var isLiveListening: Boolean = false 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 override var playingState = State.IDLE
@MainThread @MainThread
set(value) { set(value) {
if (field != value) { if (field != value) {
Timber.w("## VoiceBroadcastPlayer state: $field -> $value") Timber.w("playingState: $field -> $value")
field = value field = value
onPlayingStateChanged(value) onPlayingStateChanged(value)
} }
} }
/** Map voiceBroadcastId to listeners.*/ /** Map voiceBroadcastId to listeners. */
private val listeners: MutableMap<String, CopyOnWriteArrayList<Listener>> = mutableMapOf() private val listeners: MutableMap<String, CopyOnWriteArrayList<Listener>> = mutableMapOf()
override fun playOrResume(voiceBroadcast: VoiceBroadcast) { override fun playOrResume(voiceBroadcast: VoiceBroadcast) {
@ -325,9 +333,9 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
/** /**
* Update the live listening state according to: * Update the live listening state according to:
* - the voice broadcast state, * - the voice broadcast state (started/paused/resumed/stopped),
* - the playing state, * - the playing state (IDLE, PLAYING, PAUSED, BUFFERING),
* - the potential seek position. * - the potential seek position (backward/forward).
*/ */
private fun updateLiveListeningMode(seekPosition: Int? = null) { private fun updateLiveListeningMode(seekPosition: Int? = null) {
isLiveListening = when { isLiveListening = when {
@ -348,11 +356,12 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
// otherwise, stay in live or go in live if we reached the last sequence // otherwise, stay in live or go in live if we reached the last sequence
else -> isLiveListening || playlist.currentSequence == playlist.lastOrNull()?.sequence else -> isLiveListening || playlist.currentSequence == playlist.lastOrNull()?.sequence
} }
}
private fun onLiveListeningChanged(isLiveListening: Boolean) {
currentVoiceBroadcast?.voiceBroadcastId?.let { voiceBroadcastId -> currentVoiceBroadcast?.voiceBroadcastId?.let { voiceBroadcastId ->
// Notify live mode change to all the listeners attached to the current voice broadcast id // Notify live mode change to all the listeners attached to the current voice broadcast id
listeners[voiceBroadcastId]?.forEach { listener -> listener.onLiveModeChanged(isLiveListening) } listeners[voiceBroadcastId]?.forEach { listener -> listener.onLiveModeChanged(isLiveListening) }
} }
} }