Improve playback errors UI

This commit is contained in:
vfsfitvnm
2022-08-07 12:41:27 +02:00
parent e4e53bf056
commit 073a50b34c
4 changed files with 181 additions and 102 deletions

View File

@@ -0,0 +1,9 @@
package it.vfsfitvnm.vimusic.service
import androidx.media3.common.PlaybackException
class PlayableFormatNotFoundException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR)
class UnplayableException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR)
class LoginRequiredException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR)

View File

@@ -268,10 +268,17 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
}
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
maybeRecoverPlaybackError()
maybeNormalizeVolume()
maybeProcessRadio()
}
private fun maybeRecoverPlaybackError() {
if (player.playerError != null) {
player.prepare()
}
}
private fun maybeProcessRadio() {
radio?.let { radio ->
if (player.mediaItemCount - player.currentMediaItemIndex <= 3) {
@@ -595,11 +602,9 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
}
format.url
} ?: throw PlaybackException(
"Couldn't find a playable audio format",
null,
PlaybackException.ERROR_CODE_REMOTE_ERROR
)
} ?: throw PlayableFormatNotFoundException()
"UNPLAYABLE" -> throw UnplayableException()
"LOGIN_REQUIRED" -> throw LoginRequiredException()
else -> throw PlaybackException(
status,
null,
@@ -614,7 +619,7 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
.subrange(dataSpec.uriPositionOffset, chunkLength)
} ?: throw PlaybackException(
null,
null,
urlResult?.exceptionOrNull(),
PlaybackException.ERROR_CODE_REMOTE_ERROR
)
}