Skip to content

Commit ed4fdad

Browse files
committed
Fix OnErrorNotImplementedException in playOnPopup
1 parent 298e96b commit ed4fdad

2 files changed

Lines changed: 48 additions & 21 deletions

File tree

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,14 @@ class ErrorPanelHelper(
121121
ErrorActivity.reportError(context, errorInfo)
122122
}
123123

124-
errorTextView.setText(
125-
when (errorInfo.throwable) {
126-
is AgeRestrictedContentException -> R.string.restricted_video_no_stream
127-
is GeographicRestrictionException -> R.string.georestricted_content
128-
is PaidContentException -> R.string.paid_content
129-
is PrivateContentException -> R.string.private_content
130-
is SoundCloudGoPlusContentException -> R.string.soundcloud_go_plus_content
131-
is YoutubeMusicPremiumContentException -> R.string.youtube_music_premium_content
132-
is ContentNotAvailableException -> R.string.content_not_available
133-
is ContentNotSupportedException -> R.string.content_not_supported
134-
else -> {
135-
// show retry button only for content which is not unavailable or unsupported
136-
errorRetryButton.isVisible = true
137-
if (errorInfo.throwable != null && errorInfo.throwable!!.isNetworkRelated) {
138-
R.string.network_error
139-
} else {
140-
R.string.error_snackbar_message
141-
}
142-
}
143-
}
144-
)
124+
errorTextView.setText(getExceptionDescription(errorInfo.throwable))
125+
126+
if (errorInfo.throwable !is ContentNotAvailableException &&
127+
errorInfo.throwable !is ContentNotSupportedException
128+
) {
129+
// show retry button only for content which is not unavailable or unsupported
130+
errorRetryButton.isVisible = true
131+
}
145132
}
146133

147134
setRootVisible()
@@ -189,5 +176,27 @@ class ErrorPanelHelper(
189176
companion object {
190177
val TAG: String = ErrorPanelHelper::class.simpleName!!
191178
val DEBUG: Boolean = MainActivity.DEBUG
179+
180+
@StringRes
181+
public fun getExceptionDescription(throwable: Throwable?): Int {
182+
return when (throwable) {
183+
is AgeRestrictedContentException -> R.string.restricted_video_no_stream
184+
is GeographicRestrictionException -> R.string.georestricted_content
185+
is PaidContentException -> R.string.paid_content
186+
is PrivateContentException -> R.string.private_content
187+
is SoundCloudGoPlusContentException -> R.string.soundcloud_go_plus_content
188+
is YoutubeMusicPremiumContentException -> R.string.youtube_music_premium_content
189+
is ContentNotAvailableException -> R.string.content_not_available
190+
is ContentNotSupportedException -> R.string.content_not_supported
191+
else -> {
192+
// show retry button only for content which is not unavailable or unsupported
193+
if (throwable != null && throwable.isNetworkRelated) {
194+
R.string.network_error
195+
} else {
196+
R.string.error_snackbar_message
197+
}
198+
}
199+
}
200+
}
192201
}
193202
}

app/src/main/java/org/schabi/newpipe/util/external_communication/InternalUrlsHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package org.schabi.newpipe.util.external_communication;
22

33
import android.content.Context;
4+
import android.util.Log;
45

56
import androidx.annotation.NonNull;
7+
import androidx.appcompat.app.AlertDialog;
68

9+
import org.schabi.newpipe.MainActivity;
10+
import org.schabi.newpipe.R;
11+
import org.schabi.newpipe.error.ErrorPanelHelper;
712
import org.schabi.newpipe.extractor.NewPipe;
813
import org.schabi.newpipe.extractor.StreamingService;
914
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -24,6 +29,9 @@
2429
import io.reactivex.rxjava3.schedulers.Schedulers;
2530

2631
public final class InternalUrlsHandler {
32+
private static final String TAG = InternalUrlsHandler.class.getSimpleName();
33+
private static final boolean DEBUG = MainActivity.DEBUG;
34+
2735
private static final Pattern AMPERSAND_TIMESTAMP_PATTERN = Pattern.compile("(.*)&t=(\\d+)");
2836
private static final Pattern HASHTAG_TIMESTAMP_PATTERN =
2937
Pattern.compile("(.*)#timestamp=(\\d+)");
@@ -148,6 +156,16 @@ public static boolean playOnPopup(final Context context,
148156
final PlayQueue playQueue
149157
= new SinglePlayQueue(info, seconds * 1000);
150158
NavigationHelper.playOnPopupPlayer(context, playQueue, false);
159+
}, throwable -> {
160+
if (DEBUG) {
161+
Log.e(TAG, "Could not play on popup: " + url, throwable);
162+
}
163+
new AlertDialog.Builder(context)
164+
.setTitle(R.string.player_stream_failure)
165+
.setMessage(
166+
ErrorPanelHelper.Companion.getExceptionDescription(throwable))
167+
.setPositiveButton(R.string.ok, (v, b) -> { })
168+
.show();
151169
}));
152170
return true;
153171
}

0 commit comments

Comments
 (0)