@UnstableApi
interface LoadControl

Known direct subclasses
DefaultLoadControl

The default LoadControl implementation.


Controls buffering of media.

Summary

Nested types

Information about the current playback context and the MediaPeriod for which methods are called.

Constants

const MediaSource.MediaPeriodId!

This property is deprecated.

Used as a placeholder when MediaPeriodId is unknown.

Public functions

Allocator!

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

Long

This function is deprecated.

Implements getBackBufferDurationUs instead.

Long

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

Unit

This function is deprecated.

Use onPrepared instead.

Unit
onPrepared(playerId: PlayerId!)

Called by the player when prepared with a new source.

Unit

This function is deprecated.

Implement onReleased instead.

Unit
onReleased(playerId: PlayerId!)

Called by the player when released.

Unit

This function is deprecated.

Implement onStopped instead.

Unit
onStopped(playerId: PlayerId!)

Called by the player when stopped.

Unit
onTracksSelected(
    parameters: LoadControl.Parameters!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
)

Called by the player when a track selection occurs.

Unit
onTracksSelected(
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
)

This function is deprecated.

Implement onTracksSelected instead.

Unit
onTracksSelected(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
)

This function is deprecated.

Implement onTracksSelected instead.

Unit
onTracksSelected(
    playerId: PlayerId!,
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
)

This function is deprecated.

Implement onTracksSelected instead.

Boolean

This function is deprecated.

Implements retainBackBufferFromKeyframe instead.

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.

Boolean

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

Boolean
shouldContinueLoading(
    playbackPositionUs: Long,
    bufferedDurationUs: Long,
    playbackSpeed: Float
)

This function is deprecated.

Implement shouldContinueLoading instead.

Boolean
shouldContinuePreloading(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    bufferedDurationUs: Long
)

Called to determine whether preloading should be continued.

Boolean

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.

Boolean
shouldStartPlayback(
    bufferedDurationUs: Long,
    playbackSpeed: Float,
    rebuffering: Boolean,
    targetLiveOffsetUs: Long
)

This function is deprecated.

Implement shouldStartPlayback instead.

Boolean
shouldStartPlayback(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    bufferedDurationUs: Long,
    playbackSpeed: Float,
    rebuffering: Boolean,
    targetLiveOffsetUs: Long
)

This function is deprecated.

Implement shouldStartPlayback instead.

Constants

EMPTY_MEDIA_PERIOD_ID

const val EMPTY_MEDIA_PERIOD_IDMediaSource.MediaPeriodId!

Public functions

getAllocator

fun getAllocator(): Allocator!

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

getBackBufferDurationUs

fun getBackBufferDurationUs(): Long

getBackBufferDurationUs

fun getBackBufferDurationUs(playerId: PlayerId!): Long

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.

Parameters
playerId: PlayerId!

The ID of the player that requests the back buffer duration.

Returns
Long

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

onPrepared

fun onPrepared(): Unit

onPrepared

fun onPrepared(playerId: PlayerId!): Unit

Called by the player when prepared with a new source.

Parameters
playerId: PlayerId!

The ID of the player that prepared a new source.

onReleased

fun onReleased(): Unit

onReleased

fun onReleased(playerId: PlayerId!): Unit

Called by the player when released.

Parameters
playerId: PlayerId!

The ID of the player that was released.

onStopped

fun onStopped(): Unit

onStopped

fun onStopped(playerId: PlayerId!): Unit

Called by the player when stopped.

Parameters
playerId: PlayerId!

The ID of the player that was stopped.

onTracksSelected

fun onTracksSelected(
    parameters: LoadControl.Parameters!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
): Unit

Called by the player when a track selection occurs.

Parameters
parameters: LoadControl.Parameters!

containing the ID of the player, the current in ExoPlayer, and the MediaPeriod for which the selection was made. Will be EMPTY_MEDIA_PERIOD_ID when timeline is empty.

trackGroups: TrackGroupArray!

The TrackGroups from which the selection was made.

@NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!

The track selections that were made.

onTracksSelected

fun onTracksSelected(
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
): Unit

onTracksSelected

fun onTracksSelected(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
): Unit

onTracksSelected

fun onTracksSelected(
    playerId: PlayerId!,
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    @NullableType trackSelections: Array<@NullableType ExoTrackSelection!>!
): Unit

retainBackBufferFromKeyframe

fun retainBackBufferFromKeyframe(): Boolean

retainBackBufferFromKeyframe

fun retainBackBufferFromKeyframe(playerId: PlayerId!): 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.

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.

Parameters
playerId: PlayerId!

The ID of the player that requests whether to retain the back buffer from key frame.

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

fun shouldContinueLoading(parameters: LoadControl.Parameters!): Boolean

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
parameters: LoadControl.Parameters!

Information about the playback context and the MediaPeriod that will continue to load if this method returns true.

Returns
Boolean

Whether the loading should continue.

shouldContinueLoading

fun shouldContinueLoading(
    playbackPositionUs: Long,
    bufferedDurationUs: Long,
    playbackSpeed: Float
): Boolean

shouldContinuePreloading

fun shouldContinuePreloading(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    bufferedDurationUs: Long
): Boolean

Called to determine whether preloading should be continued. If this method returns true, the presented period will continue to load media.

Parameters
timeline: Timeline!

The Timeline containing the preload period that can be looked up with MediaPeriodId.periodUid.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaPeriodId of the preloading period.

bufferedDurationUs: Long

The duration of media currently buffered by the preload period.

Returns
Boolean

Whether the preloading should continue for the given period.

shouldStartPlayback

fun shouldStartPlayback(parameters: LoadControl.Parameters!): Boolean

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
parameters: LoadControl.Parameters!

Information about the playback context and the MediaPeriod that will start playing if this method returns true.

Returns
Boolean

Whether playback should be allowed to start or resume.

shouldStartPlayback

fun shouldStartPlayback(
    bufferedDurationUs: Long,
    playbackSpeed: Float,
    rebuffering: Boolean,
    targetLiveOffsetUs: Long
): Boolean

shouldStartPlayback

fun shouldStartPlayback(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    bufferedDurationUs: Long,
    playbackSpeed: Float,
    rebuffering: Boolean,
    targetLiveOffsetUs: Long
): Boolean