Handle download error during playback

This commit is contained in:
Florian Renaud 2023-01-10 15:16:25 +01:00
parent 2d24eb1273
commit 3663f22590

View file

@ -206,6 +206,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
val sequence = playlistItem.sequence ?: run { Timber.w("## Voice Broadcast | Playlist item has no sequence"); return }
val sequencePosition = position - playlistItem.startTime
sessionScope.launch {
try {
prepareMediaPlayer(content) { mp ->
currentMediaPlayer = mp
playlist.currentSequence = sequence
@ -216,6 +217,9 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
playingState = State.Playing
prepareNextMediaPlayer()
}
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
playingState = State.Error(failure)
}
}
}
@ -259,6 +263,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
if (nextItem != null) {
isPreparingNextPlayer = true
sessionScope.launch {
try {
prepareMediaPlayer(nextItem.audioEvent.content) { mp ->
isPreparingNextPlayer = false
nextMediaPlayer = mp
@ -275,6 +280,12 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
State.Idle -> stopPlayer()
}
}
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
isPreparingNextPlayer = false
if (playingState == State.Buffering || tryOrNull { currentMediaPlayer?.isPlaying } != true) {
playingState = State.Error(failure)
}
}
}
}
}