Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigating long buffering on initial video playback #7919

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -91,6 +93,7 @@ public DashMediaSource.Factory getDashMediaSourceFactory() {

public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.setContinueLoadingCheckIntervalBytes(continueLoadingCheckIntervalBytes)
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -391,6 +392,19 @@ public static boolean globalScreenOrientationLocked(final Context context) {
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
////////////////////////////////////////////////////////////////////////////
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@
<item>30000</item>
</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>
karyogamy marked this conversation as resolved.
Show resolved Hide resolved
<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_value">@string/minimize_on_exit_background_key</string>
<string name="minimize_on_exit_none_key">minimize_on_exit_none_key</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
<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="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_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>
Expand Down Expand Up @@ -717,4 +719,6 @@
<!-- Show Channel Details -->
<string name="error_show_channel_details">Error at Show 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>
10 changes: 10 additions & 0 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
app:singleLineTitle="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
android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_player_title"
Expand Down