From 31814b70dad2ff3e5aeefc4098495d60cbc2cbc7 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:34:10 +0300 Subject: [PATCH] Disabled preloading when switching streams --- .../newpipe/fragments/detail/VideoDetailFragment.java | 3 +++ .../java/org/schabi/newpipe/player/BasePlayer.java | 5 +++++ .../org/schabi/newpipe/player/VideoPlayerImpl.java | 4 ++++ .../schabi/newpipe/player/helper/LoadController.java | 11 +++++++++++ 4 files changed, 23 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index b92becbd1..61a52bd69 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -958,6 +958,9 @@ public class VideoDetailFragment return; } setInitialData(sid, videoUrl, title, queue); + if (player != null) { + player.disablePreloadingOfCurrentTrack(); + } startLoading(false, true); } 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 5e0f9ab94..f126e88a0 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -1410,6 +1410,11 @@ public abstract class BasePlayer implements return currentMetadata; } + @NonNull + public LoadController getLoadController() { + return (LoadController) loadControl; + } + @NonNull public String getVideoUrl() { return currentMetadata == null diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 0e06c1aaf..080013ae4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -1484,6 +1484,10 @@ public class VideoPlayerImpl extends VideoPlayer } } + public void disablePreloadingOfCurrentTrack() { + getLoadController().disablePreloadingOfCurrentTrack(); + } + /** * Measures width and height of controls visible on screen. * It ensures that controls will be side-by-side with NavigationBar and notches diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java index e164e0563..d123a263b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java @@ -13,6 +13,7 @@ public class LoadController implements LoadControl { private final long initialPlaybackBufferUs; private final LoadControl internalLoadControl; + private boolean preloadingEnabled = true; /*////////////////////////////////////////////////////////////////////////// // Default Load Control @@ -41,6 +42,7 @@ public class LoadController implements LoadControl { @Override public void onPrepared() { + preloadingEnabled = true; internalLoadControl.onPrepared(); } @@ -52,11 +54,13 @@ public class LoadController implements LoadControl { @Override public void onStopped() { + preloadingEnabled = true; internalLoadControl.onStopped(); } @Override public void onReleased() { + preloadingEnabled = true; internalLoadControl.onReleased(); } @@ -78,6 +82,9 @@ public class LoadController implements LoadControl { @Override public boolean shouldContinueLoading(final long bufferedDurationUs, final float playbackSpeed) { + if (!preloadingEnabled) { + return false; + } return internalLoadControl.shouldContinueLoading(bufferedDurationUs, playbackSpeed); } @@ -90,4 +97,8 @@ public class LoadController implements LoadControl { .shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering); return isInitialPlaybackBufferFilled || isInternalStartingPlayback; } + + public void disablePreloadingOfCurrentTrack() { + preloadingEnabled = false; + } }