From 9c9730b15217c7e8d3b2ccdecd658361215ccae3 Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 14 Nov 2021 20:12:12 +0100 Subject: [PATCH] Use DefaultLoadcontrol --- .../newpipe/player/helper/LoadController.java | 74 ++----------------- .../newpipe/player/helper/PlayerHelper.java | 7 -- 2 files changed, 5 insertions(+), 76 deletions(-) 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 ca3b1a3c1..ec0e4e4a7 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 @@ -1,81 +1,28 @@ package org.schabi.newpipe.player.helper; import com.google.android.exoplayer2.DefaultLoadControl; -import com.google.android.exoplayer2.LoadControl; -import com.google.android.exoplayer2.Renderer; -import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.trackselection.ExoTrackSelection; -import com.google.android.exoplayer2.upstream.Allocator; -public class LoadController implements LoadControl { +public class LoadController extends DefaultLoadControl { public static final String TAG = "LoadController"; - - private final long initialPlaybackBufferUs; - private final LoadControl internalLoadControl; private boolean preloadingEnabled = true; - /*////////////////////////////////////////////////////////////////////////// - // Default Load Control - //////////////////////////////////////////////////////////////////////////*/ - - public LoadController() { - this(PlayerHelper.getPlaybackStartBufferMs()); - } - - private LoadController(final int initialPlaybackBufferMs) { - this.initialPlaybackBufferUs = initialPlaybackBufferMs * 1000; - - final DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder(); - builder.setBufferDurationsMs( - DefaultLoadControl.DEFAULT_MIN_BUFFER_MS, - DefaultLoadControl.DEFAULT_MAX_BUFFER_MS, - initialPlaybackBufferMs, - DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS); - internalLoadControl = builder.build(); - } - - /*////////////////////////////////////////////////////////////////////////// - // Custom behaviours - //////////////////////////////////////////////////////////////////////////*/ - @Override public void onPrepared() { preloadingEnabled = true; - internalLoadControl.onPrepared(); - } - - @Override - public void onTracksSelected(final Renderer[] renderers, final TrackGroupArray trackGroups, - final ExoTrackSelection[] trackSelections) { - internalLoadControl.onTracksSelected(renderers, trackGroups, trackSelections); + super.onPrepared(); } @Override public void onStopped() { preloadingEnabled = true; - internalLoadControl.onStopped(); + super.onStopped(); } @Override public void onReleased() { preloadingEnabled = true; - internalLoadControl.onReleased(); - } - - @Override - public Allocator getAllocator() { - return internalLoadControl.getAllocator(); - } - - @Override - public long getBackBufferDurationUs() { - return internalLoadControl.getBackBufferDurationUs(); - } - - @Override - public boolean retainBackBufferFromKeyframe() { - return internalLoadControl.retainBackBufferFromKeyframe(); + super.onReleased(); } @Override @@ -85,21 +32,10 @@ public class LoadController implements LoadControl { if (!preloadingEnabled) { return false; } - return internalLoadControl.shouldContinueLoading( + return super.shouldContinueLoading( playbackPositionUs, bufferedDurationUs, playbackSpeed); } - @Override - public boolean shouldStartPlayback(final long bufferedDurationUs, final float playbackSpeed, - final boolean rebuffering, final long targetLiveOffsetUs) { - final boolean isInitialPlaybackBufferFilled - = bufferedDurationUs >= this.initialPlaybackBufferUs * playbackSpeed; - final boolean isInternalStartingPlayback = internalLoadControl - .shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering, - targetLiveOffsetUs); - return isInitialPlaybackBufferFilled || isInternalStartingPlayback; - } - public void disablePreloadingOfCurrentTrack() { preloadingEnabled = false; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 6cb94336b..c51b6d5dd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -305,13 +305,6 @@ public final class PlayerHelper { return 2 * 1024 * 1024L; // ExoPlayer CacheDataSink.MIN_RECOMMENDED_FRAGMENT_SIZE } - /** - * @return the number of milliseconds the player buffers for before starting playback - */ - public static int getPlaybackStartBufferMs() { - return 500; - } - public static ExoTrackSelection.Factory getQualitySelector() { return new AdaptiveTrackSelection.Factory( 1000,