From ab45efceabca302c486d44bd2a3f904067916c19 Mon Sep 17 00:00:00 2001 From: karyogamy Date: Sun, 20 Feb 2022 18:07:15 -0500 Subject: [PATCH 1/2] - added: variable load check interval for progressive stream. - added: preferences to allow user setting of above. --- .../newpipe/player/helper/PlayerDataSource.java | 3 +++ .../newpipe/player/helper/PlayerHelper.java | 14 ++++++++++++++ app/src/main/res/values/settings_keys.xml | 17 +++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/video_audio_settings.xml | 10 ++++++++++ 5 files changed, 48 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java index a2f0d7149..d7a9ffc3d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java @@ -31,11 +31,13 @@ public class PlayerDataSource { private static final int MANIFEST_MINIMUM_RETRY = 5; private static final int EXTRACTOR_MINIMUM_RETRY = Integer.MAX_VALUE; + private final int continueLoadingCheckIntervalBytes; private final DataSource.Factory cacheDataSourceFactory; private final DataSource.Factory cachelessDataSourceFactory; public PlayerDataSource(@NonNull final Context context, @NonNull final String userAgent, @NonNull final TransferListener transferListener) { + continueLoadingCheckIntervalBytes = PlayerHelper.getProgressiveLoadIntervalBytes(context); cacheDataSourceFactory = new CacheFactory(context, userAgent, transferListener); cachelessDataSourceFactory = new DefaultDataSourceFactory(context, userAgent, transferListener); @@ -91,6 +93,7 @@ public class PlayerDataSource { public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() { return new ProgressiveMediaSource.Factory(cacheDataSourceFactory) + .setContinueLoadingCheckIntervalBytes(continueLoadingCheckIntervalBytes) .setLoadErrorHandlingPolicy( new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY)); } 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 c51b6d5dd..6a7c27bdc 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 @@ -34,6 +34,7 @@ import androidx.preference.PreferenceManager; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player.RepeatMode; import com.google.android.exoplayer2.SeekParameters; +import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.ExoTrackSelection; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; @@ -391,6 +392,19 @@ public final class PlayerHelper { context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0; } + public static int getProgressiveLoadIntervalBytes(@NonNull final Context context) { + final String preferredIntervalBytes = getPreferences(context).getString( + context.getString(R.string.progressive_load_interval_key), + context.getString(R.string.progressive_load_interval_default_value)); + + if (context.getString(R.string.progressive_load_interval_default_value) + .equals(preferredIntervalBytes)) { + return ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES; + } + // Keeping the same KiB unit used by ProgressiveMediaSource + return Integer.parseInt(preferredIntervalBytes) * 1024; + } + //////////////////////////////////////////////////////////////////////////// // Private helpers //////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 5e9fc2220..8f9879489 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -55,6 +55,23 @@ 30000 + progressive_load_interval + default + + 1 KiB + 16 KiB + 64 KiB + 256 KiB + @string/progressive_load_interval_default + + + 1 + 16 + 64 + 256 + default + + minimize_on_exit_key @string/minimize_on_exit_background_key minimize_on_exit_none_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96b99bfd2..abf82d481 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -78,6 +78,8 @@ Use fast inexact seek Inexact seek allows the player to seek to positions faster with reduced precision. Seeking for 5, 15 or 25 seconds doesn\'t work with this Fast-forward/-rewind seek duration + Playback load interval size + Change the load interval size (currently at %s). A lower value may speed up initial video loading. Changes require a player restart. Ask for confirmation before clearing a queue Switching from one player to another may replace your queue The active player queue will be replaced @@ -717,4 +719,6 @@ Error at Show Channel Details Loading Channel Details… + + ExoPlayer default \ No newline at end of file diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index 4dc5d5c9a..3f90011a9 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -206,6 +206,16 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + Date: Tue, 1 Mar 2022 20:14:40 +0100 Subject: [PATCH 2/2] Minor rework * Moved settings to a better section * Made string a bit shorter --- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/video_audio_settings.xml | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index abf82d481..8b8945b40 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,7 +79,7 @@ Inexact seek allows the player to seek to positions faster with reduced precision. Seeking for 5, 15 or 25 seconds doesn\'t work with this Fast-forward/-rewind seek duration Playback load interval size - Change the load interval size (currently at %s). A lower value may speed up initial video loading. Changes require a player restart. + Change the load interval size (currently %s). A lower value may speed up initial video loading. Changes require a player restart. Ask for confirmation before clearing a queue Switching from one player to another may replace your queue The active player queue will be replaced diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index 3f90011a9..69013ae4b 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -61,6 +61,16 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + - -