From a00bc95acccd5c4c253726ecb4decb21d8cd228f Mon Sep 17 00:00:00 2001 From: karyogamy Date: Sun, 27 Mar 2022 13:24:37 -0400 Subject: [PATCH] updated: source loading error for FailedMediaSource to wait for 3 seconds before allowing retry. updated: minor style fixes. --- app/src/main/java/org/schabi/newpipe/player/Player.java | 7 +++++-- .../newpipe/player/mediasource/FailedMediaSource.java | 2 +- .../schabi/newpipe/player/playback/MediaSourceManager.java | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) 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 ba4c4f237..c4205124c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -2487,11 +2487,11 @@ public final class Player implements /** *

Listens for event or state changes on ExoPlayer. When any event happens, we check for * changes in the currently-playing metadata and update the encapsulating - * {@link Player}. Downstream listeners are also informed. + * {@link Player}. Downstream listeners are also informed.

* *

When the renewed metadata contains any error, it is reported as a notification. * This is done because not all source resolution errors are {@link PlaybackException}, which - * are also captured by {@link ExoPlayer} and stops the playback. + * are also captured by {@link ExoPlayer} and stops the playback.

* * @param player The {@link com.google.android.exoplayer2.Player} whose state changed. * @param events The {@link com.google.android.exoplayer2.Player.Events} that has triggered @@ -2634,6 +2634,9 @@ public final class Player implements * * @see com.google.android.exoplayer2.Player.Listener#onPlayerError(PlaybackException) * */ + // Any error code not explicitly covered here are either unrelated to NewPipe use case + // (e.g. DRM) or not recoverable (e.g. Decoder error). In both cases, the player should + // shutdown. @SuppressLint("SwitchIntDef") @Override public void onPlayerError(@NonNull final PlaybackException error) { diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java index fa52ab0ee..8aad356d0 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java @@ -78,7 +78,7 @@ public class FailedMediaSource extends BaseMediaSource implements ManagedMediaSo return playQueueItem; } - public Throwable getError() { + public Exception getError() { return error; } diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java b/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java index b4e9a15ab..9b13bb3d7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java @@ -441,8 +441,10 @@ public class MediaSourceManager { if (throwable instanceof ExtractionException) { return FailedMediaSource.of(stream, new StreamInfoLoadException(throwable)); } - return FailedMediaSource - .of(stream, new Exception(throwable), /*immediatelyRetryable=*/0L); + // Non-source related error expected here (e.g. network), + // should allow retry shortly after the error. + return FailedMediaSource.of(stream, new Exception(throwable), + /*allowRetryIn=*/TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS)); }); }