1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-04-14 19:01:22 +00:00

- added: variable load check interval for progressive stream.

- added: preferences to allow user setting of above.
This commit is contained in:
karyogamy
2022-02-20 18:07:15 -05:00
committed by litetex
parent cbdcf5905f
commit ab45efceab
5 changed files with 48 additions and 0 deletions

View File

@@ -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));
}

View File

@@ -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
////////////////////////////////////////////////////////////////////////////