Remove PlayerErrorHandler and correctly set ErrorInfo msg

This commit is contained in:
Stypox 2021-12-02 14:24:45 +01:00
parent 397f93b079
commit c8e2ab4c83
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
6 changed files with 24 additions and 117 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -89,8 +89,6 @@
<item>@string/never</item>
</string-array>
<string name="report_player_errors_key" translatable="false">report_player_errors_key</string>
<string name="seekbar_preview_thumbnail_key" translatable="false">seekbar_preview_thumbnail_key</string>
<string name="seekbar_preview_thumbnail_high_quality" translatable="false">seekbar_preview_thumbnail_high_quality</string>
<string name="seekbar_preview_thumbnail_low_quality" translatable="false">seekbar_preview_thumbnail_low_quality</string>

View file

@ -53,8 +53,6 @@
<string name="show_play_with_kodi_title">Show \"Play with Kodi\" option</string>
<string name="show_play_with_kodi_summary">Display an option to play a video via Kodi media center</string>
<string name="crash_the_player">Crash the player</string>
<string name="report_player_errors_title">Report player errors</string>
<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>
<string name="notification_scale_to_square_image_title">Scale thumbnail to 1:1 aspect ratio</string>
<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>
<string name="notification_action_0_title">First action button</string>

View file

@ -49,14 +49,6 @@
android:title="@string/show_image_indicators_title"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/report_player_errors_key"
android:summary="@string/report_player_errors_summary"
android:title="@string/report_player_errors_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
<Preference
android:key="@string/crash_the_app_key"
android:title="@string/crash_the_app"