mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 01:00:55 +01:00
Fix issue on live playback detection
This commit is contained in:
parent
d092c83774
commit
9dba6d7c8c
@ -66,7 +66,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
private var nextMediaPlayer: MediaPlayer? = null
|
private var nextMediaPlayer: MediaPlayer? = null
|
||||||
private var isPreparingNextPlayer: Boolean = false
|
private var isPreparingNextPlayer: Boolean = false
|
||||||
|
|
||||||
private var currentVoiceBroadcastEvent: VoiceBroadcastEvent? = null
|
private var mostRecentVoiceBroadcastEvent: VoiceBroadcastEvent? = null
|
||||||
|
|
||||||
override var currentVoiceBroadcast: VoiceBroadcast? = null
|
override var currentVoiceBroadcast: VoiceBroadcast? = null
|
||||||
override var isLiveListening: Boolean = false
|
override var isLiveListening: Boolean = false
|
||||||
@ -121,7 +121,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
// Clear playlist
|
// Clear playlist
|
||||||
playlist.reset()
|
playlist.reset()
|
||||||
|
|
||||||
currentVoiceBroadcastEvent = null
|
mostRecentVoiceBroadcastEvent = null
|
||||||
currentVoiceBroadcast = null
|
currentVoiceBroadcast = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
if (event == null) {
|
if (event == null) {
|
||||||
stop()
|
stop()
|
||||||
} else {
|
} else {
|
||||||
currentVoiceBroadcastEvent = event
|
mostRecentVoiceBroadcastEvent = event
|
||||||
updateLiveListeningMode()
|
updateLiveListeningMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
|
|
||||||
val playlistItem = when {
|
val playlistItem = when {
|
||||||
position != null -> playlist.findByPosition(position)
|
position != null -> playlist.findByPosition(position)
|
||||||
currentVoiceBroadcastEvent?.isLive.orFalse() -> playlist.lastOrNull()
|
mostRecentVoiceBroadcastEvent?.isLive.orFalse() -> playlist.lastOrNull()
|
||||||
else -> playlist.firstOrNull()
|
else -> playlist.firstOrNull()
|
||||||
}
|
}
|
||||||
val content = playlistItem?.audioEvent?.content ?: run { Timber.w("## VoiceBroadcastPlayer: No content to play"); return }
|
val content = playlistItem?.audioEvent?.content ?: run { Timber.w("## VoiceBroadcastPlayer: No content to play"); return }
|
||||||
@ -346,7 +346,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
private fun updateLiveListeningMode(seekPosition: Int? = null) {
|
private fun updateLiveListeningMode(seekPosition: Int? = null) {
|
||||||
isLiveListening = when {
|
isLiveListening = when {
|
||||||
// the current voice broadcast is not live (ended)
|
// the current voice broadcast is not live (ended)
|
||||||
currentVoiceBroadcastEvent?.isLive?.not().orFalse() -> false
|
mostRecentVoiceBroadcastEvent?.isLive != true -> false
|
||||||
// the player is stopped or paused
|
// the player is stopped or paused
|
||||||
playingState == State.IDLE || playingState == State.PAUSED -> false
|
playingState == State.IDLE || playingState == State.PAUSED -> false
|
||||||
seekPosition != null -> {
|
seekPosition != null -> {
|
||||||
@ -412,13 +412,11 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||||||
override fun onCompletion(mp: MediaPlayer) {
|
override fun onCompletion(mp: MediaPlayer) {
|
||||||
if (nextMediaPlayer != null) return
|
if (nextMediaPlayer != null) return
|
||||||
|
|
||||||
val content = currentVoiceBroadcastEvent?.content
|
if (isLiveListening || mostRecentVoiceBroadcastEvent?.content?.lastChunkSequence == playlist.currentSequence) {
|
||||||
val isLive = content?.isLive.orFalse()
|
playingState = State.BUFFERING
|
||||||
if (!isLive && content?.lastChunkSequence == playlist.currentSequence) {
|
} else {
|
||||||
// We'll not receive new chunks anymore so we can stop the live listening
|
// We'll not receive new chunks anymore so we can stop the live listening
|
||||||
stop()
|
stop()
|
||||||
} else {
|
|
||||||
playingState = State.BUFFERING
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user