Skip to content

Commit 651b79d

Browse files
committed
Catch properly BehindLiveWindowExceptions
Instead of trying to reload the play queue manager and then throwing an error, BehindLiveWindowExceptions now make the app seek to the default playback position, like recommended by ExoPlayer. The buffering state is shown in this case. Error handling of other exceptions is not changed.
1 parent 9e5b9ca commit 651b79d

1 file changed

Lines changed: 43 additions & 18 deletions

File tree

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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,50 +2517,75 @@ public void onPlayerError(@NonNull final ExoPlaybackException error) {
25172517
Log.e(TAG, "ExoPlayer - onPlayerError() called with:", error);
25182518

25192519
saveStreamProgressState();
2520-
2521-
// create error notification
2522-
final ErrorInfo errorInfo;
2523-
if (currentMetadata == null) {
2524-
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2525-
"Player error[type=" + error.type + "] occurred, currentMetadata is null");
2526-
} else {
2527-
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2528-
"Player error[type=" + error.type + "] occurred while playing "
2529-
+ currentMetadata.getMetadata().getUrl(),
2530-
currentMetadata.getMetadata());
2531-
}
2532-
ErrorUtil.createNotification(context, errorInfo);
2520+
boolean isBehindLiveWindowException = false;
25332521

25342522
switch (error.type) {
25352523
case ExoPlaybackException.TYPE_SOURCE:
2536-
processSourceError(error.getSourceException());
2524+
isBehindLiveWindowException = processSourceError(error.getSourceException());
2525+
if (!isBehindLiveWindowException) {
2526+
createErrorNotification(error);
2527+
}
25372528
break;
25382529
case ExoPlaybackException.TYPE_UNEXPECTED:
2530+
createErrorNotification(error);
25392531
setRecovery();
25402532
reloadPlayQueueManager();
25412533
break;
25422534
case ExoPlaybackException.TYPE_REMOTE:
25432535
case ExoPlaybackException.TYPE_RENDERER:
25442536
default:
2537+
createErrorNotification(error);
25452538
onPlaybackShutdown();
25462539
break;
25472540
}
25482541

2549-
if (fragmentListener != null) {
2542+
if (fragmentListener != null && !isBehindLiveWindowException) {
25502543
fragmentListener.onPlayerError(error);
25512544
}
25522545
}
25532546

2554-
private void processSourceError(final IOException error) {
2547+
private void createErrorNotification(@NonNull final ExoPlaybackException error) {
2548+
final ErrorInfo errorInfo;
2549+
if (currentMetadata == null) {
2550+
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2551+
"Player error[type=" + error.type + "] occurred, currentMetadata is null");
2552+
} else {
2553+
errorInfo = new ErrorInfo(error, UserAction.PLAY_STREAM,
2554+
"Player error[type=" + error.type + "] occurred while playing "
2555+
+ currentMetadata.getMetadata().getUrl(),
2556+
currentMetadata.getMetadata());
2557+
}
2558+
ErrorUtil.createNotification(context, errorInfo);
2559+
}
2560+
2561+
/**
2562+
* Process an {@link IOException} returned by {@link ExoPlaybackException#getSourceException()}
2563+
* for {@link ExoPlaybackException#TYPE_SOURCE} exceptions.
2564+
*
2565+
* <p>
2566+
* This method sets the recovery position and sends an error message to the play queue if the
2567+
* exception is not a {@link BehindLiveWindowException}.
2568+
* </p>
2569+
* @param error the source error which was thrown by ExoPlayer
2570+
* @return whether the exception thrown is a {@link BehindLiveWindowException} ({@code false}
2571+
* is always returned if ExoPlayer or the play queue is null)
2572+
*/
2573+
private boolean processSourceError(final IOException error) {
25552574
if (exoPlayerIsNull() || playQueue == null) {
2556-
return;
2575+
return false;
25572576
}
2577+
25582578
setRecovery();
25592579

25602580
if (error instanceof BehindLiveWindowException) {
2561-
reloadPlayQueueManager();
2581+
simpleExoPlayer.seekToDefaultPosition();
2582+
simpleExoPlayer.prepare();
2583+
// Inform the user that we are reloading the stream by switching to the buffering state
2584+
onBuffering();
2585+
return true;
25622586
} else {
25632587
playQueue.error();
2588+
return false;
25642589
}
25652590
}
25662591
//endregion

0 commit comments

Comments
 (0)