Merge pull request #7919 from karyogamy/progress-load-interval
Mitigating long buffering on initial video playback
This commit is contained in:
commit
b8e389c6e8
|
@ -31,11 +31,13 @@ public class PlayerDataSource {
|
||||||
private static final int MANIFEST_MINIMUM_RETRY = 5;
|
private static final int MANIFEST_MINIMUM_RETRY = 5;
|
||||||
private static final int EXTRACTOR_MINIMUM_RETRY = Integer.MAX_VALUE;
|
private static final int EXTRACTOR_MINIMUM_RETRY = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
private final int continueLoadingCheckIntervalBytes;
|
||||||
private final DataSource.Factory cacheDataSourceFactory;
|
private final DataSource.Factory cacheDataSourceFactory;
|
||||||
private final DataSource.Factory cachelessDataSourceFactory;
|
private final DataSource.Factory cachelessDataSourceFactory;
|
||||||
|
|
||||||
public PlayerDataSource(@NonNull final Context context, @NonNull final String userAgent,
|
public PlayerDataSource(@NonNull final Context context, @NonNull final String userAgent,
|
||||||
@NonNull final TransferListener transferListener) {
|
@NonNull final TransferListener transferListener) {
|
||||||
|
continueLoadingCheckIntervalBytes = PlayerHelper.getProgressiveLoadIntervalBytes(context);
|
||||||
cacheDataSourceFactory = new CacheFactory(context, userAgent, transferListener);
|
cacheDataSourceFactory = new CacheFactory(context, userAgent, transferListener);
|
||||||
cachelessDataSourceFactory
|
cachelessDataSourceFactory
|
||||||
= new DefaultDataSourceFactory(context, userAgent, transferListener);
|
= new DefaultDataSourceFactory(context, userAgent, transferListener);
|
||||||
|
@ -91,6 +93,7 @@ public class PlayerDataSource {
|
||||||
|
|
||||||
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
|
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
|
||||||
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||||
|
.setContinueLoadingCheckIntervalBytes(continueLoadingCheckIntervalBytes)
|
||||||
.setLoadErrorHandlingPolicy(
|
.setLoadErrorHandlingPolicy(
|
||||||
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
|
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import androidx.preference.PreferenceManager;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
import com.google.android.exoplayer2.Player.RepeatMode;
|
import com.google.android.exoplayer2.Player.RepeatMode;
|
||||||
import com.google.android.exoplayer2.SeekParameters;
|
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.AdaptiveTrackSelection;
|
||||||
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
|
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
|
@ -391,6 +392,19 @@ public final class PlayerHelper {
|
||||||
context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
|
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
|
// Private helpers
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -55,6 +55,23 @@
|
||||||
<item>30000</item>
|
<item>30000</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string name="progressive_load_interval_key">progressive_load_interval</string>
|
||||||
|
<string name="progressive_load_interval_default_value">default</string>
|
||||||
|
<string-array name="progressive_load_interval_descriptions">
|
||||||
|
<item>1 KiB</item>
|
||||||
|
<item>16 KiB</item>
|
||||||
|
<item>64 KiB</item>
|
||||||
|
<item>256 KiB</item>
|
||||||
|
<item>@string/progressive_load_interval_default</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="progressive_load_interval_values">
|
||||||
|
<item>1</item>
|
||||||
|
<item>16</item>
|
||||||
|
<item>64</item>
|
||||||
|
<item>256</item>
|
||||||
|
<item>default</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="minimize_on_exit_key">minimize_on_exit_key</string>
|
<string name="minimize_on_exit_key">minimize_on_exit_key</string>
|
||||||
<string name="minimize_on_exit_value">@string/minimize_on_exit_background_key</string>
|
<string name="minimize_on_exit_value">@string/minimize_on_exit_background_key</string>
|
||||||
<string name="minimize_on_exit_none_key">minimize_on_exit_none_key</string>
|
<string name="minimize_on_exit_none_key">minimize_on_exit_none_key</string>
|
||||||
|
|
|
@ -78,6 +78,8 @@
|
||||||
<string name="use_inexact_seek_title">Use fast inexact seek</string>
|
<string name="use_inexact_seek_title">Use fast inexact seek</string>
|
||||||
<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>
|
<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>
|
||||||
<string name="seek_duration_title">Fast-forward/-rewind seek duration</string>
|
<string name="seek_duration_title">Fast-forward/-rewind seek duration</string>
|
||||||
|
<string name="progressive_load_interval_title">Playback load interval size</string>
|
||||||
|
<string name="progressive_load_interval_summary">Change the load interval size (currently %s). A lower value may speed up initial video loading. Changes require a player restart.</string>
|
||||||
<string name="clear_queue_confirmation_title">Ask for confirmation before clearing a queue</string>
|
<string name="clear_queue_confirmation_title">Ask for confirmation before clearing a queue</string>
|
||||||
<string name="clear_queue_confirmation_summary">Switching from one player to another may replace your queue</string>
|
<string name="clear_queue_confirmation_summary">Switching from one player to another may replace your queue</string>
|
||||||
<string name="clear_queue_confirmation_description">The active player queue will be replaced</string>
|
<string name="clear_queue_confirmation_description">The active player queue will be replaced</string>
|
||||||
|
@ -717,4 +719,6 @@
|
||||||
<!-- Show Channel Details -->
|
<!-- Show Channel Details -->
|
||||||
<string name="error_show_channel_details">Error at Show Channel Details</string>
|
<string name="error_show_channel_details">Error at Show Channel Details</string>
|
||||||
<string name="loading_channel_details">Loading Channel Details…</string>
|
<string name="loading_channel_details">Loading Channel Details…</string>
|
||||||
|
<!-- Progressive Load Interval -->
|
||||||
|
<string name="progressive_load_interval_default">ExoPlayer default</string>
|
||||||
</resources>
|
</resources>
|
|
@ -61,6 +61,16 @@
|
||||||
app:singleLineTitle="false"
|
app:singleLineTitle="false"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/progressive_load_interval_default_value"
|
||||||
|
android:entries="@array/progressive_load_interval_descriptions"
|
||||||
|
android:entryValues="@array/progressive_load_interval_values"
|
||||||
|
android:key="@string/progressive_load_interval_key"
|
||||||
|
android:summary="@string/progressive_load_interval_summary"
|
||||||
|
android:title="@string/progressive_load_interval_title"
|
||||||
|
app:singleLineTitle="false"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:layout="@layout/settings_category_header_layout"
|
android:layout="@layout/settings_category_header_layout"
|
||||||
android:title="@string/settings_category_player_title"
|
android:title="@string/settings_category_player_title"
|
||||||
|
|
Loading…
Reference in New Issue