From c8e2ab4c83f93a3ce3561a30f53f584af40dce2e Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 2 Dec 2021 14:24:45 +0100 Subject: [PATCH] Remove PlayerErrorHandler and correctly set ErrorInfo msg --- .../org/schabi/newpipe/error/ErrorInfo.kt | 8 ++ .../org/schabi/newpipe/player/Player.java | 33 ++++--- .../playererror/PlayerErrorHandler.java | 88 ------------------- app/src/main/res/values/settings_keys.xml | 2 - app/src/main/res/values/strings.xml | 2 - app/src/main/res/xml/debug_settings.xml | 8 -- 6 files changed, 24 insertions(+), 117 deletions(-) delete mode 100644 app/src/main/java/org/schabi/newpipe/player/playererror/PlayerErrorHandler.java diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt index ba1204e12..b2ba912ec 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt @@ -2,6 +2,7 @@ package org.schabi.newpipe.error import android.os.Parcelable import androidx.annotation.StringRes +import com.google.android.exoplayer2.ExoPlaybackException import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import org.schabi.newpipe.R @@ -108,6 +109,13 @@ class ErrorInfo( throwable is ContentNotSupportedException -> R.string.content_not_supported throwable is DeobfuscateException -> R.string.youtube_signature_deobfuscation_error throwable is ExtractionException -> R.string.parsing_error + throwable is ExoPlaybackException -> { + when (throwable.type) { + ExoPlaybackException.TYPE_SOURCE -> R.string.player_stream_failure + ExoPlaybackException.TYPE_UNEXPECTED -> R.string.player_recoverable_failure + else -> R.string.player_unrecoverable_failure + } + } action == UserAction.UI_ERROR -> R.string.app_ui_crash action == UserAction.REQUESTED_COMMENTS -> R.string.error_unable_to_load_comments action == UserAction.SUBSCRIPTION_CHANGE -> R.string.subscription_change_failed diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 2d8c1a830..ee09cb866 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -141,6 +141,9 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.PlayerBinding; import org.schabi.newpipe.databinding.PlayerPopupCloseOverlayBinding; +import org.schabi.newpipe.error.ErrorInfo; +import org.schabi.newpipe.error.ErrorUtil; +import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamSegment; @@ -165,7 +168,6 @@ import org.schabi.newpipe.player.playback.MediaSourceManager; import org.schabi.newpipe.player.playback.PlaybackListener; import org.schabi.newpipe.player.playback.PlayerMediaSession; import org.schabi.newpipe.player.playback.SurfaceHolderCallback; -import org.schabi.newpipe.player.playererror.PlayerErrorHandler; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueueAdapter; import org.schabi.newpipe.player.playqueue.PlayQueueItem; @@ -268,8 +270,6 @@ public final class Player implements @Nullable private MediaSourceTag currentMetadata; @Nullable private Bitmap currentThumbnail; - @NonNull private PlayerErrorHandler playerErrorHandler; - /*////////////////////////////////////////////////////////////////////////// // Player //////////////////////////////////////////////////////////////////////////*/ @@ -413,8 +413,6 @@ public final class Player implements videoResolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver()); audioResolver = new AudioPlaybackResolver(context, dataSource); - playerErrorHandler = new PlayerErrorHandler(context); - windowManager = ContextCompat.getSystemService(context, WindowManager.class); } @@ -2518,29 +2516,30 @@ public final class Player implements saveStreamProgressState(); + // create error notification + final ErrorInfo errorInfo; + if (currentMetadata == null) { + errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM, + "Player error[type=" + error.type + "] occurred, currentMetadata is null"); + } else { + errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM, + "Player error[type=" + error.type + "] occurred while playing " + + currentMetadata.getMetadata().getUrl(), + currentMetadata.getMetadata()); + } + ErrorUtil.createNotification(context, errorInfo); + switch (error.type) { case ExoPlaybackException.TYPE_SOURCE: processSourceError(error.getSourceException()); - playerErrorHandler.showPlayerError( - error, - currentMetadata.getMetadata(), - R.string.player_stream_failure); break; case ExoPlaybackException.TYPE_UNEXPECTED: - playerErrorHandler.showPlayerError( - error, - currentMetadata.getMetadata(), - R.string.player_recoverable_failure); setRecovery(); reloadPlayQueueManager(); break; case ExoPlaybackException.TYPE_REMOTE: case ExoPlaybackException.TYPE_RENDERER: default: - playerErrorHandler.showPlayerError( - error, - currentMetadata.getMetadata(), - R.string.player_unrecoverable_failure); onPlaybackShutdown(); break; } diff --git a/app/src/main/java/org/schabi/newpipe/player/playererror/PlayerErrorHandler.java b/app/src/main/java/org/schabi/newpipe/player/playererror/PlayerErrorHandler.java deleted file mode 100644 index ca9b4e7df..000000000 --- a/app/src/main/java/org/schabi/newpipe/player/playererror/PlayerErrorHandler.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.schabi.newpipe.player.playererror; - -import android.content.Context; -import android.util.Log; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.preference.PreferenceManager; - -import com.google.android.exoplayer2.ExoPlaybackException; - -import org.schabi.newpipe.R; -import org.schabi.newpipe.error.ErrorInfo; -import org.schabi.newpipe.error.ErrorUtil; -import org.schabi.newpipe.error.UserAction; -import org.schabi.newpipe.extractor.Info; - -/** - * Handles (exoplayer)errors that occur in the player. - */ -public class PlayerErrorHandler { - // This has to be <= 23 chars on devices running Android 7 or lower (API <= 25) - // or it fails with an IllegalArgumentException - // https://stackoverflow.com/a/54744028 - private static final String TAG = "PlayerErrorHandler"; - - @Nullable - private Toast errorToast; - - @NonNull - private final Context context; - - public PlayerErrorHandler(@NonNull final Context context) { - this.context = context; - } - - public void showPlayerError( - @NonNull final ExoPlaybackException exception, - @NonNull final Info info, - @StringRes final int textResId - ) { - // Hide existing toast message - if (errorToast != null) { - Log.d(TAG, "Trying to cancel previous player error error toast"); - errorToast.cancel(); - errorToast = null; - } - - if (shouldReportError()) { - try { - reportError(exception, info); - // When a report pops up we need no toast - return; - } catch (final Exception ex) { - Log.w(TAG, "Unable to report error:", ex); - // This will show the toast as fallback - } - } - - Log.d(TAG, "Showing player error toast"); - errorToast = Toast.makeText(context, textResId, Toast.LENGTH_SHORT); - errorToast.show(); - } - - private void reportError(@NonNull final ExoPlaybackException exception, - @NonNull final Info info) { - ErrorUtil.createNotification( - context, - new ErrorInfo( - exception, - UserAction.PLAY_STREAM, - "Player error[type=" + exception.type + "] occurred while playing: " - + info.getUrl(), - info - ) - ); - } - - private boolean shouldReportError() { - return PreferenceManager - .getDefaultSharedPreferences(context) - .getBoolean( - context.getString(R.string.report_player_errors_key), - false); - } -} diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index e2b797576..b88b2d064 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -89,8 +89,6 @@ @string/never - report_player_errors_key - seekbar_preview_thumbnail_key seekbar_preview_thumbnail_high_quality seekbar_preview_thumbnail_low_quality diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f47322b79..3319d5fb9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -53,8 +53,6 @@ Show \"Play with Kodi\" option Display an option to play a video via Kodi media center Crash the player - Report player errors - Reports player errors in full detail instead of showing a short-lived toast message (useful for diagnosing problems) Scale thumbnail to 1:1 aspect ratio Scale the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio (may introduce distortions) First action button diff --git a/app/src/main/res/xml/debug_settings.xml b/app/src/main/res/xml/debug_settings.xml index 5e2cc28ed..df1559c37 100644 --- a/app/src/main/res/xml/debug_settings.xml +++ b/app/src/main/res/xml/debug_settings.xml @@ -49,14 +49,6 @@ android:title="@string/show_image_indicators_title" app:iconSpaceReserved="false" /> - -