Skip to content

Commit c8e2ab4

Browse files
committed
Remove PlayerErrorHandler and correctly set ErrorInfo msg
1 parent 397f93b commit c8e2ab4

6 files changed

Lines changed: 24 additions & 117 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.schabi.newpipe.error
22

33
import android.os.Parcelable
44
import androidx.annotation.StringRes
5+
import com.google.android.exoplayer2.ExoPlaybackException
56
import kotlinx.parcelize.IgnoredOnParcel
67
import kotlinx.parcelize.Parcelize
78
import org.schabi.newpipe.R
@@ -108,6 +109,13 @@ class ErrorInfo(
108109
throwable is ContentNotSupportedException -> R.string.content_not_supported
109110
throwable is DeobfuscateException -> R.string.youtube_signature_deobfuscation_error
110111
throwable is ExtractionException -> R.string.parsing_error
112+
throwable is ExoPlaybackException -> {
113+
when (throwable.type) {
114+
ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure
115+
ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure
116+
else -> R.string.player_unrecoverable_failure
117+
}
118+
}
111119
action == UserAction.UI_ERROR -> R.string.app_ui_crash
112120
action == UserAction.REQUESTED_COMMENTS -> R.string.error_unable_to_load_comments
113121
action == UserAction.SUBSCRIPTION_CHANGE -> R.string.subscription_change_failed

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
import org.schabi.newpipe.R;
142142
import org.schabi.newpipe.databinding.PlayerBinding;
143143
import org.schabi.newpipe.databinding.PlayerPopupCloseOverlayBinding;
144+
import org.schabi.newpipe.error.ErrorInfo;
145+
import org.schabi.newpipe.error.ErrorUtil;
146+
import org.schabi.newpipe.error.UserAction;
144147
import org.schabi.newpipe.extractor.MediaFormat;
145148
import org.schabi.newpipe.extractor.stream.StreamInfo;
146149
import org.schabi.newpipe.extractor.stream.StreamSegment;
@@ -165,7 +168,6 @@
165168
import org.schabi.newpipe.player.playback.PlaybackListener;
166169
import org.schabi.newpipe.player.playback.PlayerMediaSession;
167170
import org.schabi.newpipe.player.playback.SurfaceHolderCallback;
168-
import org.schabi.newpipe.player.playererror.PlayerErrorHandler;
169171
import org.schabi.newpipe.player.playqueue.PlayQueue;
170172
import org.schabi.newpipe.player.playqueue.PlayQueueAdapter;
171173
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
@@ -268,8 +270,6 @@ public final class Player implements
268270
@Nullable private MediaSourceTag currentMetadata;
269271
@Nullable private Bitmap currentThumbnail;
270272

271-
@NonNull private PlayerErrorHandler playerErrorHandler;
272-
273273
/*//////////////////////////////////////////////////////////////////////////
274274
// Player
275275
//////////////////////////////////////////////////////////////////////////*/
@@ -413,8 +413,6 @@ public Player(@NonNull final MainPlayer service) {
413413
videoResolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver());
414414
audioResolver = new AudioPlaybackResolver(context, dataSource);
415415

416-
playerErrorHandler = new PlayerErrorHandler(context);
417-
418416
windowManager = ContextCompat.getSystemService(context, WindowManager.class);
419417
}
420418

@@ -2518,29 +2516,30 @@ public void onPlayerError(@NonNull final ExoPlaybackException error) {
25182516

25192517
saveStreamProgressState();
25202518

2519+
// create error notification
2520+
final ErrorInfo errorInfo;
2521+
if (currentMetadata == null) {
2522+
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2523+
"Player error[type=" + error.type + "] occurred, currentMetadata is null");
2524+
} else {
2525+
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2526+
"Player error[type=" + error.type + "] occurred while playing "
2527+
+ currentMetadata.getMetadata().getUrl(),
2528+
currentMetadata.getMetadata());
2529+
}
2530+
ErrorUtil.createNotification(context, errorInfo);
2531+
25212532
switch (error.type) {
25222533
case ExoPlaybackException.TYPE_SOURCE:
25232534
processSourceError(error.getSourceException());
2524-
playerErrorHandler.showPlayerError(
2525-
error,
2526-
currentMetadata.getMetadata(),
2527-
R.string.player_stream_failure);
25282535
break;
25292536
case ExoPlaybackException.TYPE_UNEXPECTED:
2530-
playerErrorHandler.showPlayerError(
2531-
error,
2532-
currentMetadata.getMetadata(),
2533-
R.string.player_recoverable_failure);
25342537
setRecovery();
25352538
reloadPlayQueueManager();
25362539
break;
25372540
case ExoPlaybackException.TYPE_REMOTE:
25382541
case ExoPlaybackException.TYPE_RENDERER:
25392542
default:
2540-
playerErrorHandler.showPlayerError(
2541-
error,
2542-
currentMetadata.getMetadata(),
2543-
R.string.player_unrecoverable_failure);
25442543
onPlaybackShutdown();
25452544
break;
25462545
}

app/src/main/java/org/schabi/newpipe/player/playererror/PlayerErrorHandler.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@
8989
<item>@string/never</item>
9090
</string-array>
9191

92-
<string name="report_player_errors_key" translatable="false">report_player_errors_key</string>
93-
9492
<string name="seekbar_preview_thumbnail_key" translatable="false">seekbar_preview_thumbnail_key</string>
9593
<string name="seekbar_preview_thumbnail_high_quality" translatable="false">seekbar_preview_thumbnail_high_quality</string>
9694
<string name="seekbar_preview_thumbnail_low_quality" translatable="false">seekbar_preview_thumbnail_low_quality</string>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
<string name="show_play_with_kodi_title">Show \"Play with Kodi\" option</string>
5454
<string name="show_play_with_kodi_summary">Display an option to play a video via Kodi media center</string>
5555
<string name="crash_the_player">Crash the player</string>
56-
<string name="report_player_errors_title">Report player errors</string>
57-
<string name="report_player_errors_summary">Reports player errors in full detail instead of showing a short-lived toast message (useful for diagnosing problems)</string>
5856
<string name="notification_scale_to_square_image_title">Scale thumbnail to 1:1 aspect ratio</string>
5957
<string name="notification_scale_to_square_image_summary">Scale the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio (may introduce distortions)</string>
6058
<string name="notification_action_0_title">First action button</string>

app/src/main/res/xml/debug_settings.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@
4949
android:title="@string/show_image_indicators_title"
5050
app:iconSpaceReserved="false" />
5151

52-
<SwitchPreferenceCompat
53-
android:defaultValue="false"
54-
android:key="@string/report_player_errors_key"
55-
android:summary="@string/report_player_errors_summary"
56-
android:title="@string/report_player_errors_title"
57-
app:singleLineTitle="false"
58-
app:iconSpaceReserved="false" />
59-
6052
<Preference
6153
android:key="@string/crash_the_app_key"
6254
android:title="@string/crash_the_app"

0 commit comments

Comments
 (0)