Add comment to explain the error handling

This commit is contained in:
Florian Renaud 2023-01-12 18:29:56 +01:00
parent 9d3b5c5bbb
commit 8a2f28bc37
1 changed files with 4 additions and 0 deletions

View File

@ -282,6 +282,8 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
}
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
isPreparingNextPlayer = false
// Do not change the playingState if the current player is still valid,
// the error will be thrown again when switching to the next player
if (playingState == State.Buffering || tryOrNull { currentMediaPlayer?.isPlaying } != true) {
playingState = State.Error(failure)
}
@ -453,6 +455,8 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
override fun onError(mp: MediaPlayer, what: Int, extra: Int): Boolean {
Timber.d("## Voice Broadcast | onError: what=$what, extra=$extra")
// Do not change the playingState if the current player is still valid,
// the error will be thrown again when switching to the next player
if (playingState == State.Buffering || tryOrNull { currentMediaPlayer?.isPlaying } != true) {
playingState = State.Error(VoiceBroadcastFailure.ListeningError.UnableToPlay(what, extra))
}