Skip to content

Commit 3663f22

Browse files
author
Florian Renaud
committed
Handle download error during playback
1 parent 2d24eb1 commit 3663f22

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,19 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
206206
val sequence = playlistItem.sequence ?: run { Timber.w("## Voice Broadcast | Playlist item has no sequence"); return }
207207
val sequencePosition = position - playlistItem.startTime
208208
sessionScope.launch {
209-
prepareMediaPlayer(content) { mp ->
210-
currentMediaPlayer = mp
211-
playlist.currentSequence = sequence
212-
mp.start()
213-
if (sequencePosition > 0) {
214-
mp.seekTo(sequencePosition)
209+
try {
210+
prepareMediaPlayer(content) { mp ->
211+
currentMediaPlayer = mp
212+
playlist.currentSequence = sequence
213+
mp.start()
214+
if (sequencePosition > 0) {
215+
mp.seekTo(sequencePosition)
216+
}
217+
playingState = State.Playing
218+
prepareNextMediaPlayer()
215219
}
216-
playingState = State.Playing
217-
prepareNextMediaPlayer()
220+
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
221+
playingState = State.Error(failure)
218222
}
219223
}
220224
}
@@ -259,20 +263,27 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
259263
if (nextItem != null) {
260264
isPreparingNextPlayer = true
261265
sessionScope.launch {
262-
prepareMediaPlayer(nextItem.audioEvent.content) { mp ->
263-
isPreparingNextPlayer = false
264-
nextMediaPlayer = mp
265-
when (playingState) {
266-
State.Playing,
267-
State.Paused -> {
268-
currentMediaPlayer?.setNextMediaPlayer(mp)
266+
try {
267+
prepareMediaPlayer(nextItem.audioEvent.content) { mp ->
268+
isPreparingNextPlayer = false
269+
nextMediaPlayer = mp
270+
when (playingState) {
271+
State.Playing,
272+
State.Paused -> {
273+
currentMediaPlayer?.setNextMediaPlayer(mp)
274+
}
275+
State.Buffering -> {
276+
mp.start()
277+
onNextMediaPlayerStarted(mp)
278+
}
279+
is State.Error,
280+
State.Idle -> stopPlayer()
269281
}
270-
State.Buffering -> {
271-
mp.start()
272-
onNextMediaPlayerStarted(mp)
273-
}
274-
is State.Error,
275-
State.Idle -> stopPlayer()
282+
}
283+
} catch (failure: VoiceBroadcastFailure.ListeningError.DownloadError) {
284+
isPreparingNextPlayer = false
285+
if (playingState == State.Buffering || tryOrNull { currentMediaPlayer?.isPlaying } != true) {
286+
playingState = State.Error(failure)
276287
}
277288
}
278289
}

0 commit comments

Comments
 (0)