mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2025-10-03 17:59:41 +02:00
Show better information about player errors
This commit is contained in:
parent
38064be702
commit
29a3ca83b5
3 changed files with 18 additions and 9 deletions
|
@ -23,6 +23,8 @@ import org.schabi.newpipe.extractor.exceptions.UnsupportedContentInCountryExcept
|
||||||
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException
|
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException
|
||||||
import org.schabi.newpipe.extractor.exceptions.YoutubeSignInConfirmNotBotException
|
import org.schabi.newpipe.extractor.exceptions.YoutubeSignInConfirmNotBotException
|
||||||
import org.schabi.newpipe.ktx.isNetworkRelated
|
import org.schabi.newpipe.ktx.isNetworkRelated
|
||||||
|
import org.schabi.newpipe.player.mediasource.FailedMediaSource
|
||||||
|
import org.schabi.newpipe.player.resolver.PlaybackResolver
|
||||||
import org.schabi.newpipe.util.ServiceHelper
|
import org.schabi.newpipe.util.ServiceHelper
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
@ -97,9 +99,9 @@ class ErrorInfo(
|
||||||
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)
|
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
private fun getMessageStringId(
|
fun getMessageStringId(
|
||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
action: UserAction
|
action: UserAction?
|
||||||
): Int {
|
): Int {
|
||||||
return when {
|
return when {
|
||||||
// content not available exceptions
|
// content not available exceptions
|
||||||
|
@ -123,14 +125,19 @@ class ErrorInfo(
|
||||||
throwable != null && throwable.isNetworkRelated -> R.string.network_error
|
throwable != null && throwable.isNetworkRelated -> R.string.network_error
|
||||||
throwable is ExtractionException -> R.string.parsing_error
|
throwable is ExtractionException -> R.string.parsing_error
|
||||||
|
|
||||||
// ExoPlayer exceptions
|
// player exceptions
|
||||||
throwable is ExoPlaybackException -> {
|
throwable is ExoPlaybackException -> {
|
||||||
when (throwable.type) {
|
val cause = throwable.cause
|
||||||
ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure
|
when {
|
||||||
ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure
|
cause is HttpDataSource.InvalidResponseCodeException && cause.responseCode == 403 -> R.string.player_error_403
|
||||||
|
cause is Loader.UnexpectedLoaderException && cause.cause is ExtractionException -> getMessageStringId(throwable, action)
|
||||||
|
throwable.type == ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure
|
||||||
|
throwable.type == ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure
|
||||||
else -> R.string.player_unrecoverable_failure
|
else -> R.string.player_unrecoverable_failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throwable is FailedMediaSource.FailedMediaSourceException -> getMessageStringId(throwable.cause, action)
|
||||||
|
throwable is PlaybackResolver.ResolverException -> R.string.player_stream_failure
|
||||||
|
|
||||||
// user actions (in case the exception is unrecognizable)
|
// user actions (in case the exception is unrecognizable)
|
||||||
action == UserAction.UI_ERROR -> R.string.app_ui_crash
|
action == UserAction.UI_ERROR -> R.string.app_ui_crash
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.NewPipeDatabase
|
import org.schabi.newpipe.NewPipeDatabase
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
import org.schabi.newpipe.error.ErrorInfo
|
||||||
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler
|
||||||
|
@ -84,7 +85,7 @@ class MediaBrowserPlaybackPreparer(
|
||||||
},
|
},
|
||||||
{ throwable ->
|
{ throwable ->
|
||||||
Log.e(TAG, "Failed to start playback of media ID [$mediaId]", throwable)
|
Log.e(TAG, "Failed to start playback of media ID [$mediaId]", throwable)
|
||||||
onPrepareError()
|
onPrepareError(throwable)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -115,9 +116,9 @@ class MediaBrowserPlaybackPreparer(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPrepareError() {
|
private fun onPrepareError(throwable: Throwable) {
|
||||||
setMediaSessionError.accept(
|
setMediaSessionError.accept(
|
||||||
ContextCompat.getString(context, R.string.error_snackbar_message),
|
ContextCompat.getString(context, ErrorInfo.getMessageStringId(throwable, null)),
|
||||||
PlaybackStateCompat.ERROR_CODE_APP_ERROR
|
PlaybackStateCompat.ERROR_CODE_APP_ERROR
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -877,6 +877,7 @@
|
||||||
<string name="trending_movies">Trending movies and shows</string>
|
<string name="trending_movies">Trending movies and shows</string>
|
||||||
<string name="trending_music">Trending music</string>
|
<string name="trending_music">Trending music</string>
|
||||||
<string name="entry_deleted">Entry deleted</string>
|
<string name="entry_deleted">Entry deleted</string>
|
||||||
|
<string name="player_error_403">HTTP error 403 occurred while playing, likely caused by an IP ban or streaming URL deobfuscation issues</string>
|
||||||
<string name="youtube_sign_in_confirm_not_bot_error">YouTube refused to provide data, asking for a login.\n\nYour IP might have been temporarily banned by YouTube, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).</string>
|
<string name="youtube_sign_in_confirm_not_bot_error">YouTube refused to provide data, asking for a login.\n\nYour IP might have been temporarily banned by YouTube, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).</string>
|
||||||
<string name="unsupported_content_in_country">This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\".</string>
|
<string name="unsupported_content_in_country">This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\".</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue