mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Handle download error during playback
This commit is contained in:
parent
2d24eb1273
commit
3663f22590
1 changed files with 32 additions and 21 deletions
|
@ -206,15 +206,19 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
||||||
val sequence = playlistItem.sequence ?: run { Timber.w("## Voice Broadcast | Playlist item has no sequence"); return }
|
val sequence = playlistItem.sequence ?: run { Timber.w("## Voice Broadcast | Playlist item has no sequence"); return }
|
||||||
val sequencePosition = position - playlistItem.startTime
|
val sequencePosition = position - playlistItem.startTime
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
prepareMediaPlayer(content) { mp ->
|
try {
|
||||||
currentMediaPlayer = mp
|
prepareMediaPlayer(content) { mp ->
|
||||||
playlist.currentSequence = sequence
|
currentMediaPlayer = mp
|
||||||
mp.start()
|
playlist.currentSequence = sequence
|
||||||
if (sequencePosition > 0) {
|
mp.start()
|
||||||
mp.seekTo(sequencePosition)
|
if (sequencePosition > 0) {
|
||||||
|
mp.seekTo(sequencePosition)
|
||||||
|
}
|
||||||
|
playingState = State.Playing
|
||||||
|
prepareNextMediaPlayer()
|
||||||
}
|
}
|
||||||
playingState = State.Playing
|
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
|
||||||
prepareNextMediaPlayer()
|
playingState = State.Error(failure)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,20 +263,27 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
||||||
if (nextItem != null) {
|
if (nextItem != null) {
|
||||||
isPreparingNextPlayer = true
|
isPreparingNextPlayer = true
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
prepareMediaPlayer(nextItem.audioEvent.content) { mp ->
|
try {
|
||||||
|
prepareMediaPlayer(nextItem.audioEvent.content) { mp ->
|
||||||
|
isPreparingNextPlayer = false
|
||||||
|
nextMediaPlayer = mp
|
||||||
|
when (playingState) {
|
||||||
|
State.Playing,
|
||||||
|
State.Paused -> {
|
||||||
|
currentMediaPlayer?.setNextMediaPlayer(mp)
|
||||||
|
}
|
||||||
|
State.Buffering -> {
|
||||||
|
mp.start()
|
||||||
|
onNextMediaPlayerStarted(mp)
|
||||||
|
}
|
||||||
|
is State.Error,
|
||||||
|
State.Idle -> stopPlayer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
|
||||||
isPreparingNextPlayer = false
|
isPreparingNextPlayer = false
|
||||||
nextMediaPlayer = mp
|
if (playingState == State.Buffering || tryOrNull { currentMediaPlayer?.isPlaying } != true) {
|
||||||
when (playingState) {
|
playingState = State.Error(failure)
|
||||||
State.Playing,
|
|
||||||
State.Paused -> {
|
|
||||||
currentMediaPlayer?.setNextMediaPlayer(mp)
|
|
||||||
}
|
|
||||||
State.Buffering -> {
|
|
||||||
mp.start()
|
|
||||||
onNextMediaPlayerStarted(mp)
|
|
||||||
}
|
|
||||||
is State.Error,
|
|
||||||
State.Idle -> stopPlayer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue