Customize the look-ahead buffer (Android)
Set the buffer size of media.
Look-ahead buffer customization allows the size of a buffer of the media to download before beginning playback to be specified. Smaller buffers will start playback more quickly but will be more prone to pausing playback to buffer if the connection is not stable.
As shown in the following example, you can customize the look-ahead buffer size by creating an object that implements androidx.media3.exoplayer.LoadControl
and passing that object through ExoPlayerSettings
.
// Create a LoadControl object
LoadControl loadControl = new LoadControl() {
@Override
public void onPrepared() {
}
@Override
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, ExoTrackSelection[] trackSelections) {
}
@Override
public void onStopped() {
}
@Override
public void onReleased() {
}
@Override
public Allocator getAllocator() {
return null;
}
@Override
public long getBackBufferDurationUs() {
return 0;
}
@Override
public boolean retainBackBufferFromKeyframe() {
return false;
}
@Override
public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
return false;
}
@Override
public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs) {
return false;
}
};
// Set it up to the player right before JWPlayer#setup() is called
player.getExoPlayerSettings().setLoadControl(loadControl);
// Setup the player config
PlayerConfig playerConfig = new PlayerConfig.Builder()
//...
.build();
player.setup(playerConfig);
Updated 10 months ago