Skip to content

Commit 88fc95b

Browse files
committed
- added: variable load check interval for progressive stream.
- added: preferences to allow user setting of above.
1 parent af80d96 commit 88fc95b

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java

+3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public class PlayerDataSource {
3131
private static final int MANIFEST_MINIMUM_RETRY = 5;
3232
private static final int EXTRACTOR_MINIMUM_RETRY = Integer.MAX_VALUE;
3333

34+
private final int continueLoadingCheckIntervalBytes;
3435
private final DataSource.Factory cacheDataSourceFactory;
3536
private final DataSource.Factory cachelessDataSourceFactory;
3637

3738
public PlayerDataSource(@NonNull final Context context, @NonNull final String userAgent,
3839
@NonNull final TransferListener transferListener) {
40+
continueLoadingCheckIntervalBytes = PlayerHelper.getProgressiveLoadIntervalBytes(context);
3941
cacheDataSourceFactory = new CacheFactory(context, userAgent, transferListener);
4042
cachelessDataSourceFactory
4143
= new DefaultDataSourceFactory(context, userAgent, transferListener);
@@ -91,6 +93,7 @@ public DashMediaSource.Factory getDashMediaSourceFactory() {
9193

9294
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
9395
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
96+
.setContinueLoadingCheckIntervalBytes(continueLoadingCheckIntervalBytes)
9497
.setLoadErrorHandlingPolicy(
9598
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
9699
}

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.android.exoplayer2.PlaybackParameters;
3535
import com.google.android.exoplayer2.Player.RepeatMode;
3636
import com.google.android.exoplayer2.SeekParameters;
37+
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
3738
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
3839
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
3940
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
@@ -391,6 +392,19 @@ public static boolean globalScreenOrientationLocked(final Context context) {
391392
context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
392393
}
393394

395+
public static int getProgressiveLoadIntervalBytes(@NonNull final Context context) {
396+
final String preferredIntervalBytes = getPreferences(context).getString(
397+
context.getString(R.string.progressive_load_interval_key),
398+
context.getString(R.string.progressive_load_interval_default_value));
399+
400+
if (context.getString(R.string.progressive_load_interval_default_value)
401+
.equals(preferredIntervalBytes)) {
402+
return ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
403+
}
404+
// Keeping the same KiB unit used by ProgressiveMediaSource
405+
return Integer.parseInt(preferredIntervalBytes) * 1024;
406+
}
407+
394408
////////////////////////////////////////////////////////////////////////////
395409
// Private helpers
396410
////////////////////////////////////////////////////////////////////////////

app/src/main/res/values/settings_keys.xml

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
5555
<item>30000</item>
5656
</string-array>
5757

58+
<string name="progressive_load_interval_key">progressive_load_interval</string>
59+
<string name="progressive_load_interval_default_value">default</string>
60+
<string-array name="progressive_load_interval_descriptions">
61+
<item>1 KiB</item>
62+
<item>16 KiB</item>
63+
<item>64 KiB</item>
64+
<item>256 KiB</item>
65+
<item>@string/progressive_load_interval_default</item>
66+
</string-array>
67+
<string-array name="progressive_load_interval_values">
68+
<item>1</item>
69+
<item>16</item>
70+
<item>64</item>
71+
<item>256</item>
72+
<item>default</item>
73+
</string-array>
74+
5875
<string name="minimize_on_exit_key">minimize_on_exit_key</string>
5976
<string name="minimize_on_exit_value">@string/minimize_on_exit_background_key</string>
6077
<string name="minimize_on_exit_none_key">minimize_on_exit_none_key</string>

app/src/main/res/values/strings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
<string name="use_inexact_seek_title">Use fast inexact seek</string>
7979
<string name="use_inexact_seek_summary">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</string>
8080
<string name="seek_duration_title">Fast-forward/-rewind seek duration</string>
81+
<string name="progressive_load_interval_title">Playback load interval size</string>
82+
<string name="progressive_load_interval_summary">Change the load interval size (currently at %s). A lower value may speed up initial video loading. Changes require a player restart.</string>
8183
<string name="clear_queue_confirmation_title">Ask for confirmation before clearing a queue</string>
8284
<string name="clear_queue_confirmation_summary">Switching from one player to another may replace your queue</string>
8385
<string name="clear_queue_confirmation_description">The active player queue will be replaced</string>
@@ -702,4 +704,6 @@
702704
<!-- Show Channel Details -->
703705
<string name="error_show_channel_details">Error at Show Channel Details</string>
704706
<string name="loading_channel_details">Loading Channel Details…</string>
707+
<!-- Progressive Load Interval -->
708+
<string name="progressive_load_interval_default">ExoPlayer default</string>
705709
</resources>

app/src/main/res/xml/video_audio_settings.xml

+10
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@
206206
app:singleLineTitle="false"
207207
app:iconSpaceReserved="false" />
208208

209+
<ListPreference
210+
android:defaultValue="@string/progressive_load_interval_default_value"
211+
android:entries="@array/progressive_load_interval_descriptions"
212+
android:entryValues="@array/progressive_load_interval_values"
213+
android:key="@string/progressive_load_interval_key"
214+
android:summary="@string/progressive_load_interval_summary"
215+
android:title="@string/progressive_load_interval_title"
216+
app:singleLineTitle="false"
217+
app:iconSpaceReserved="false" />
218+
209219
<SwitchPreferenceCompat
210220
android:defaultValue="false"
211221
android:key="@string/clear_queue_confirmation_key"

0 commit comments

Comments
 (0)