@UnstableApi
public interface LoadControl

Known direct subclasses
DefaultLoadControl

The default LoadControl implementation.


Controls buffering of media.

Summary

Constants

default static final MediaSource.MediaPeriodId

This field is deprecated.

Used as a placeholder when MediaPeriodId is unknown.

Public methods

abstract Allocator

Returns the Allocator that should be used to obtain media buffer allocations.

abstract long

Returns the duration of media to retain in the buffer prior to the current playback position, for fast backward seeking.

abstract void

Called by the player when prepared with a new source.

abstract void

Called by the player when released.

abstract void

Called by the player when stopped.

default void
onTracksSelected(
    Renderer[] renderers,
    TrackGroupArray trackGroups,
    ExoTrackSelection[] trackSelections
)

This method is deprecated.

Implement onTracksSelected instead.

default void
onTracksSelected(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    Renderer[] renderers,
    TrackGroupArray trackGroups,
    ExoTrackSelection[] trackSelections
)

Called by the player when a track selection occurs.

abstract boolean

Returns whether media should be retained from the keyframe before the current playback position minus getBackBufferDurationUs, rather than any sample before or at that position.

abstract boolean
shouldContinueLoading(
    long playbackPositionUs,
    long bufferedDurationUs,
    float playbackSpeed
)

Called by the player to determine whether it should continue to load the source.

default boolean
shouldStartPlayback(
    long bufferedDurationUs,
    float playbackSpeed,
    boolean rebuffering,
    long targetLiveOffsetUs
)

This method is deprecated.

Implement shouldStartPlayback instead.

default boolean
shouldStartPlayback(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    long bufferedDurationUs,
    float playbackSpeed,
    boolean rebuffering,
    long targetLiveOffsetUs
)

Called repeatedly by the player when it's loading the source, has yet to start playback, and has the minimum amount of data necessary for playback to be started.

Constants

EMPTY_MEDIA_PERIOD_ID

default static final MediaSource.MediaPeriodId EMPTY_MEDIA_PERIOD_ID

Public methods

getAllocator

abstract Allocator getAllocator()

Returns the Allocator that should be used to obtain media buffer allocations.

getBackBufferDurationUs

abstract long getBackBufferDurationUs()

Returns the duration of media to retain in the buffer prior to the current playback position, for fast backward seeking.

Note: If retainBackBufferFromKeyframe is false then seeking in the back-buffer will only be fast if the back-buffer contains a keyframe prior to the seek position.

Note: Implementations should return a single value. Dynamic changes to the back-buffer are not currently supported.

Returns
long

The duration of media to retain in the buffer prior to the current playback position, in microseconds.

onPrepared

abstract void onPrepared()

Called by the player when prepared with a new source.

onReleased

abstract void onReleased()

Called by the player when released.

onStopped

abstract void onStopped()

Called by the player when stopped.

onTracksSelected

default void onTracksSelected(
    Renderer[] renderers,
    TrackGroupArray trackGroups,
    ExoTrackSelection[] trackSelections
)

onTracksSelected

default void onTracksSelected(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    Renderer[] renderers,
    TrackGroupArray trackGroups,
    ExoTrackSelection[] trackSelections
)

Called by the player when a track selection occurs.

Parameters
Timeline timeline

The current Timeline in ExoPlayer. Can be EMPTY only when the deprecated onTracksSelected was called.

MediaSource.MediaPeriodId mediaPeriodId

Identifies (in the current timeline) the MediaPeriod for which the selection was made. Will be EMPTY_MEDIA_PERIOD_ID when timeline is empty.

Renderer[] renderers

The renderers.

TrackGroupArray trackGroups

The TrackGroups from which the selection was made.

ExoTrackSelection[] trackSelections

The track selections that were made.

retainBackBufferFromKeyframe

abstract boolean retainBackBufferFromKeyframe()

Returns whether media should be retained from the keyframe before the current playback position minus getBackBufferDurationUs, rather than any sample before or at that position.

Warning: Returning true will cause the back-buffer size to depend on the spacing of keyframes in the media being played. Returning true is not recommended unless you control the media and are comfortable with the back-buffer size exceeding getBackBufferDurationUs by as much as the maximum duration between adjacent keyframes in the media.

Note: Implementations should return a single value. Dynamic changes to the back-buffer are not currently supported.

Returns
boolean

Whether media should be retained from the keyframe before the current playback position minus getBackBufferDurationUs, rather than any sample before or at that position.

shouldContinueLoading

abstract boolean shouldContinueLoading(
    long playbackPositionUs,
    long bufferedDurationUs,
    float playbackSpeed
)

Called by the player to determine whether it should continue to load the source. If this method returns true, the MediaPeriod identified in the most recent onTracksSelected call will continue being loaded.

Parameters
long playbackPositionUs

The current playback position in microseconds, relative to the start of the period that will continue to be loaded if this method returns true. If playback of this period has not yet started, the value will be negative and equal in magnitude to the duration of any media in previous periods still to be played.

long bufferedDurationUs

The duration of media that's currently buffered.

float playbackSpeed

The current factor by which playback is sped up.

Returns
boolean

Whether the loading should continue.

shouldStartPlayback

default boolean shouldStartPlayback(
    long bufferedDurationUs,
    float playbackSpeed,
    boolean rebuffering,
    long targetLiveOffsetUs
)

shouldStartPlayback

default boolean shouldStartPlayback(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    long bufferedDurationUs,
    float playbackSpeed,
    boolean rebuffering,
    long targetLiveOffsetUs
)

Called repeatedly by the player when it's loading the source, has yet to start playback, and has the minimum amount of data necessary for playback to be started. The value returned determines whether playback is actually started. The load control may opt to return false until some condition has been met (e.g. a certain amount of media is buffered).

Parameters
Timeline timeline

The current Timeline in ExoPlayer. Can be EMPTY only when the deprecated shouldStartPlayback was called.

MediaSource.MediaPeriodId mediaPeriodId

Identifies (in the current timeline) the MediaPeriod for which playback will start. Will be EMPTY_MEDIA_PERIOD_ID when timeline is empty.

long bufferedDurationUs

The duration of media that's currently buffered.

float playbackSpeed

The current factor by which playback is sped up.

boolean rebuffering

Whether the player is rebuffering. A rebuffer is defined to be caused by buffer depletion rather than a user action. Hence this parameter is false during initial buffering and when buffering as a result of a seek operation.

long targetLiveOffsetUs

The desired playback position offset to the live edge in microseconds, or TIME_UNSET if the media is not a live stream or no offset is configured.

Returns
boolean

Whether playback should be allowed to start or resume.