@@ -206,15 +206,19 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
206
206
val sequence = playlistItem.sequence ? : run { Timber .w(" ## Voice Broadcast | Playlist item has no sequence" ); return }
207
207
val sequencePosition = position - playlistItem.startTime
208
208
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()
215
219
}
216
- playingState = State . Playing
217
- prepareNextMediaPlayer( )
220
+ } catch (failure : VoiceBroadcastFailure . ListeningError . DownloadError ) {
221
+ playingState = State . Error (failure )
218
222
}
219
223
}
220
224
}
@@ -259,20 +263,27 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
259
263
if (nextItem != null ) {
260
264
isPreparingNextPlayer = true
261
265
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()
269
281
}
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)
276
287
}
277
288
}
278
289
}
0 commit comments