From c24d46cf0f9b66c3d5386b3b6790128983e895d5 Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Sat, 9 Sep 2017 16:11:45 -0700 Subject: [PATCH] -Fixed seek problems caused by dynamic timeline . -Removed debouncing, players are now much more responsive. -Removed some redundant methods. --- .../org/schabi/newpipe/player/BasePlayer.java | 27 +++++++++---------- .../player/playback/PlaybackManager.java | 7 ----- .../schabi/newpipe/playlist/PlayQueue.java | 3 +-- 3 files changed, 14 insertions(+), 23 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 87c74e0b3..5e316cd2c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -534,6 +534,17 @@ public abstract class BasePlayer implements Player.EventListener, @Override public void onTimelineChanged(Timeline timeline, Object manifest) { if (DEBUG) Log.d(TAG, "onTimelineChanged(), timeline size = " + timeline.getWindowCount()); + + if (simpleExoPlayer.getCurrentWindowIndex() != playbackManager.getCurrentSourceIndex()) { + if (timeline.getWindowCount() > playbackManager.getCurrentSourceIndex()) { + if (DEBUG) Log.d(TAG, "Rewinding to correct window"); + simpleExoPlayer.seekToDefaultPosition(playbackManager.getCurrentSourceIndex()); + } + } + + if (!simpleExoPlayer.isCurrentWindowDynamic() && simpleExoPlayer.isCurrentWindowSeekable()) { + simpleExoPlayer.setPlayWhenReady(true); + } } @Override @@ -638,7 +649,6 @@ public abstract class BasePlayer implements Player.EventListener, simpleExoPlayer.prepare(playbackManager.getMediaSource()); simpleExoPlayer.seekTo(playbackManager.getCurrentSourceIndex(), videoStartPos); - simpleExoPlayer.setPlayWhenReady(false); } @Override @@ -650,20 +660,9 @@ public abstract class BasePlayer implements Player.EventListener, videoThumbnailUrl = info.thumbnail_url; videoTitle = info.name; + onTimelineChanged(simpleExoPlayer.getCurrentTimeline(), null); + initThumbnail(videoThumbnailUrl); - - if (simpleExoPlayer.getCurrentWindowIndex() != playbackManager.getCurrentSourceIndex()) { - if (DEBUG) Log.w(TAG, "Rewinding to correct window"); - if (simpleExoPlayer.getCurrentTimeline().getWindowCount() > playbackManager.getCurrentSourceIndex()) { - simpleExoPlayer.seekToDefaultPosition(playbackManager.getCurrentSourceIndex()); - } else { - if (DEBUG) Log.w(TAG, "Play Queue out of sync"); - playbackManager.reset(); - return; - } - } - - simpleExoPlayer.setPlayWhenReady(true); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java b/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java index c8eb1d2cc..c461cb9b4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java @@ -109,13 +109,6 @@ public class PlaybackManager { load(); } - public void reset() { - tryBlock(); - - resetSources(); - load(); - } - public void dispose() { if (playQueueReactor != null) playQueueReactor.cancel(); if (disposables != null) disposables.dispose(); diff --git a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java index 203ffb1a5..18ac6dacf 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java @@ -26,7 +26,6 @@ import io.reactivex.subjects.BehaviorSubject; public abstract class PlayQueue implements Serializable { private final String TAG = "PlayQueue@" + Integer.toHexString(hashCode()); - private final int INDEX_CHANGE_DEBOUNCE = 350; public static final boolean DEBUG = true; @@ -59,7 +58,7 @@ public abstract class PlayQueue implements Serializable { broadcastReceiver = Flowable.merge( streamsEventBroadcast.toFlowable(BackpressureStrategy.BUFFER), - indexEventBroadcast.toFlowable(BackpressureStrategy.BUFFER).debounce(INDEX_CHANGE_DEBOUNCE, TimeUnit.MILLISECONDS) + indexEventBroadcast.toFlowable(BackpressureStrategy.BUFFER) ).startWith(new InitEvent()); if (DEBUG) broadcastReceiver.subscribe(getSelfReporter());