From 40b60e831305d2b4ad354ee3b939d5c99dc1cbf8 Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Mon, 4 Sep 2017 05:42:34 -0700 Subject: [PATCH] -Error processing for failed video during queued playback. --- .../org/schabi/newpipe/player/BasePlayer.java | 5 ++-- .../newpipe/player/MainVideoPlayer.java | 2 +- .../newpipe/player/MediaSourceManager.java | 23 ++++++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index ab3f2d5a7..49f29afb0 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -542,6 +542,8 @@ public abstract class BasePlayer implements Player.EventListener, @Override public void onPlayerError(ExoPlaybackException error) { if (DEBUG) Log.d(TAG, "onPlayerError() called with: error = [" + error + "]"); + playbackManager.report(error); + onError(error); } @@ -598,10 +600,9 @@ public abstract class BasePlayer implements Player.EventListener, channelName = info.uploader; if (simpleExoPlayer.getCurrentWindowIndex() != windowIndex) { - Log.e(TAG, "Rewinding to correct window"); + Log.w(TAG, "Rewinding to correct window"); simpleExoPlayer.seekTo(windowIndex, windowPos); } else { - Log.d(TAG, "Correct window"); simpleExoPlayer.seekTo(windowPos); } } diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 65b7e868f..ed49e66a2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -326,7 +326,7 @@ public class MainVideoPlayer extends Activity { public void onError(Exception exception) { exception.printStackTrace(); Toast.makeText(context, "Failed to play this video", Toast.LENGTH_SHORT).show(); - finish(); + //finish(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/player/MediaSourceManager.java b/app/src/main/java/org/schabi/newpipe/player/MediaSourceManager.java index 382902064..d30484802 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MediaSourceManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/MediaSourceManager.java @@ -130,6 +130,19 @@ class MediaSourceManager { sync(); } + void report(final Exception error) { + // ignore error checking for now, just remove the current index + if (error != null && !isBlocked) { + doBlock(); + } + + final int index = playQueue.getIndex(); + remove(index); + playQueue.remove(index); + tryUnblock(); + sync(); + } + void dispose() { if (loadingReactor != null) loadingReactor.cancel(); if (playQueueReactor != null) playQueueReactor.cancel(); @@ -140,7 +153,6 @@ class MediaSourceManager { disposables = null; } - /*////////////////////////////////////////////////////////////////////////// // Event Reactor //////////////////////////////////////////////////////////////////////////*/ @@ -181,7 +193,7 @@ class MediaSourceManager { } if (!isPlayQueueReady() && !isBlocked) { - playbackListener.block(); + doBlock(); playQueue.fetch(); } if (playQueueReactor != null) playQueueReactor.request(1); @@ -209,6 +221,11 @@ class MediaSourceManager { return getCurrentSourceIndex() != -1; } + private void doBlock() { + playbackListener.block(); + isBlocked = true; + } + private void tryUnblock() { if (isPlayQueueReady() && isCurrentIndexLoaded() && isBlocked) { isBlocked = false; @@ -225,7 +242,7 @@ class MediaSourceManager { if (isCurrentIndexLoaded()) { sync(); } else if (!isBlocked) { - playbackListener.block(); + doBlock(); } load();