Skip to content

Commit 29a3ca8

Browse files
committed
Show better information about player errors
1 parent 38064be commit 29a3ca8

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import org.schabi.newpipe.extractor.exceptions.UnsupportedContentInCountryExcept
2323
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException
2424
import org.schabi.newpipe.extractor.exceptions.YoutubeSignInConfirmNotBotException
2525
import org.schabi.newpipe.ktx.isNetworkRelated
26+
import org.schabi.newpipe.player.mediasource.FailedMediaSource
27+
import org.schabi.newpipe.player.resolver.PlaybackResolver
2628
import org.schabi.newpipe.util.ServiceHelper
2729

2830
@Parcelize
@@ -97,9 +99,9 @@ class ErrorInfo(
9799
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)
98100

99101
@StringRes
100-
private fun getMessageStringId(
102+
fun getMessageStringId(
101103
throwable: Throwable?,
102-
action: UserAction
104+
action: UserAction?
103105
): Int {
104106
return when {
105107
// content not available exceptions
@@ -123,14 +125,19 @@ class ErrorInfo(
123125
throwable != null && throwable.isNetworkRelated -> R.string.network_error
124126
throwable is ExtractionException -> R.string.parsing_error
125127

126-
// ExoPlayer exceptions
128+
// player exceptions
127129
throwable is ExoPlaybackException -> {
128-
when (throwable.type) {
129-
ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure
130-
ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure
130+
val cause = throwable.cause
131+
when {
132+
cause is HttpDataSource.InvalidResponseCodeException && cause.responseCode == 403 -> R.string.player_error_403
133+
cause is Loader.UnexpectedLoaderException && cause.cause is ExtractionException -> getMessageStringId(throwable, action)
134+
throwable.type == ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure
135+
throwable.type == ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure
131136
else -> R.string.player_unrecoverable_failure
132137
}
133138
}
139+
throwable is FailedMediaSource.FailedMediaSourceException -> getMessageStringId(throwable.cause, action)
140+
throwable is PlaybackResolver.ResolverException -> R.string.player_stream_failure
134141

135142
// user actions (in case the exception is unrecognizable)
136143
action == UserAction.UI_ERROR -> R.string.app_ui_crash

app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
1717
import org.schabi.newpipe.MainActivity
1818
import org.schabi.newpipe.NewPipeDatabase
1919
import org.schabi.newpipe.R
20+
import org.schabi.newpipe.error.ErrorInfo
2021
import org.schabi.newpipe.extractor.InfoItem.InfoType
2122
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
2223
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler
@@ -84,7 +85,7 @@ class MediaBrowserPlaybackPreparer(
8485
},
8586
{ throwable ->
8687
Log.e(TAG, "Failed to start playback of media ID [$mediaId]", throwable)
87-
onPrepareError()
88+
onPrepareError(throwable)
8889
}
8990
)
9091
}
@@ -115,9 +116,9 @@ class MediaBrowserPlaybackPreparer(
115116
)
116117
}
117118

118-
private fun onPrepareError() {
119+
private fun onPrepareError(throwable: Throwable) {
119120
setMediaSessionError.accept(
120-
ContextCompat.getString(context, R.string.error_snackbar_message),
121+
ContextCompat.getString(context, ErrorInfo.getMessageStringId(throwable, null)),
121122
PlaybackStateCompat.ERROR_CODE_APP_ERROR
122123
)
123124
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@
877877
<string name="trending_movies">Trending movies and shows</string>
878878
<string name="trending_music">Trending music</string>
879879
<string name="entry_deleted">Entry deleted</string>
880+
<string name="player_error_403">HTTP error 403 occurred while playing, likely caused by an IP ban or streaming URL deobfuscation issues</string>
880881
<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>
881882
<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>
882883
</resources>

0 commit comments

Comments
 (0)