DefaultLoadControl


@UnstableApi
class DefaultLoadControl : LoadControl


The default LoadControl implementation.

Summary

Nested types

Builder for DefaultLoadControl.

Constants

const Int

A default size in bytes for an audio buffer.

const Int

The default back buffer duration in milliseconds.

const Int

The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds.

const Int

The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds.

const Int

A default size in bytes for a camera motion buffer.

const Int

A default size in bytes for an image buffer.

const Int

The default maximum duration of media that the player will attempt to buffer, in milliseconds.

const Int

A default size in bytes for a metadata buffer.

const Int

The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds.

const Int

The buffer size in bytes that will be used as a minimum target buffer in all cases.

const Int

A default size in bytes for a muxed buffer (e.g. containing video, audio and text).

const Boolean

The default prioritization of buffer time constraints over size constraints.

const Boolean

The default for whether the back buffer is retained from the previous keyframe.

const Int

The default target buffer size in bytes.

const Int

A default size in bytes for a text buffer.

const Int

A default size in bytes for a video buffer.

Public constructors

Constructs a new instance, using the DEFAULT_* constants defined in this class.

Protected constructors

DefaultLoadControl(
    allocator: DefaultAllocator!,
    minBufferMs: Int,
    maxBufferMs: Int,
    bufferForPlaybackMs: Int,
    bufferForPlaybackAfterRebufferMs: Int,
    targetBufferBytes: Int,
    prioritizeTimeOverSizeThresholds: Boolean,
    backBufferDurationMs: Int,
    retainBackBufferFromKeyframe: Boolean
)

Public functions

Allocator!

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

Long

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

Unit
onPrepared(playerId: PlayerId!)

Called by the player when prepared with a new source.

Unit
onReleased(playerId: PlayerId!)

Called by the player when released.

Unit
onStopped(playerId: PlayerId!)

Called by the player when stopped.

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

Called by the player when a track selection occurs.

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

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.

Protected functions

Int
calculateTargetBufferBytes(
    renderers: Array<Renderer!>!,
    trackSelectionArray: Array<ExoTrackSelection!>!
)

Calculate target buffer size in bytes based on the selected tracks.

Inherited Constants

From androidx.media3.exoplayer.LoadControl
const MediaSource.MediaPeriodId!

This property is deprecated.

Used as a placeholder when MediaPeriodId is unknown.

Inherited functions

From androidx.media3.exoplayer.LoadControl
Long

This function is deprecated.

Implements getBackBufferDurationUs instead.

Unit

This function is deprecated.

Use onPrepared instead.

Unit

This function is deprecated.

Implement onReleased instead.

Unit

This function is deprecated.

Implement onStopped instead.

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

This function is deprecated.

Implement onTracksSelected instead.

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

This function is deprecated.

Implement onTracksSelected instead.

Boolean

This function is deprecated.

Implements retainBackBufferFromKeyframe instead.

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

This function is deprecated.

Implement shouldContinueLoading instead.

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

DEFAULT_AUDIO_BUFFER_SIZE

const val DEFAULT_AUDIO_BUFFER_SIZE = 13107200: Int

A default size in bytes for an audio buffer.

DEFAULT_BACK_BUFFER_DURATION_MS

const val DEFAULT_BACK_BUFFER_DURATION_MS = 0: Int

The default back buffer duration in milliseconds.

DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS

const val DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000: Int

The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action.

DEFAULT_BUFFER_FOR_PLAYBACK_MS

const val DEFAULT_BUFFER_FOR_PLAYBACK_MS = 2500: Int

The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds.

DEFAULT_CAMERA_MOTION_BUFFER_SIZE

const val DEFAULT_CAMERA_MOTION_BUFFER_SIZE = 131072: Int

A default size in bytes for a camera motion buffer.

DEFAULT_IMAGE_BUFFER_SIZE

const val DEFAULT_IMAGE_BUFFER_SIZE = 131072: Int

A default size in bytes for an image buffer.

DEFAULT_MAX_BUFFER_MS

const val DEFAULT_MAX_BUFFER_MS = 50000: Int

The default maximum duration of media that the player will attempt to buffer, in milliseconds.

DEFAULT_METADATA_BUFFER_SIZE

const val DEFAULT_METADATA_BUFFER_SIZE = 131072: Int

A default size in bytes for a metadata buffer.

DEFAULT_MIN_BUFFER_MS

const val DEFAULT_MIN_BUFFER_MS = 50000: Int

The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds.

DEFAULT_MIN_BUFFER_SIZE

const val DEFAULT_MIN_BUFFER_SIZE = 13107200: Int

The buffer size in bytes that will be used as a minimum target buffer in all cases. This is also the default target buffer before tracks are selected.

DEFAULT_MUXED_BUFFER_SIZE

const val DEFAULT_MUXED_BUFFER_SIZE = 144310272: Int

A default size in bytes for a muxed buffer (e.g. containing video, audio and text).

DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS

const val DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS = false: Boolean

The default prioritization of buffer time constraints over size constraints.

DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME

const val DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME = false: Boolean

The default for whether the back buffer is retained from the previous keyframe.

DEFAULT_TARGET_BUFFER_BYTES

const val DEFAULT_TARGET_BUFFER_BYTES = -1: Int

The default target buffer size in bytes. The value (LENGTH_UNSET) means that the load control will calculate the target buffer size based on the selected tracks.

DEFAULT_TEXT_BUFFER_SIZE

const val DEFAULT_TEXT_BUFFER_SIZE = 131072: Int

A default size in bytes for a text buffer.

DEFAULT_VIDEO_BUFFER_SIZE

const val DEFAULT_VIDEO_BUFFER_SIZE = 131072000: Int

A default size in bytes for a video buffer.

Public constructors

DefaultLoadControl

DefaultLoadControl()

Constructs a new instance, using the DEFAULT_* constants defined in this class.

Protected constructors

DefaultLoadControl

protected DefaultLoadControl(
    allocator: DefaultAllocator!,
    minBufferMs: Int,
    maxBufferMs: Int,
    bufferForPlaybackMs: Int,
    bufferForPlaybackAfterRebufferMs: Int,
    targetBufferBytes: Int,
    prioritizeTimeOverSizeThresholds: Boolean,
    backBufferDurationMs: Int,
    retainBackBufferFromKeyframe: Boolean
)

Public functions

getAllocator

fun getAllocator(): Allocator!

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

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(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(playerId: PlayerId!): Unit

Called by the player when released.

Parameters
playerId: PlayerId!

The ID of the player that was released.

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(
    playerId: PlayerId!,
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    renderers: Array<Renderer!>!,
    trackGroups: TrackGroupArray!,
    trackSelections: Array<ExoTrackSelection!>!
): Unit

Called by the player when a track selection occurs.

Parameters
playerId: PlayerId!

The ID of the player that selected tracks.

timeline: Timeline!

The current Timeline in ExoPlayer.

mediaPeriodId: MediaSource.MediaPeriodId!

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

renderers: Array<Renderer!>!

The renderers.

trackGroups: TrackGroupArray!

The TrackGroups from which the selection was made.

trackSelections: Array<ExoTrackSelection!>!

The track selections that were made.

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.

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.

Protected functions

calculateTargetBufferBytes

protected fun calculateTargetBufferBytes(
    renderers: Array<Renderer!>!,
    trackSelectionArray: Array<ExoTrackSelection!>!
): Int

Calculate target buffer size in bytes based on the selected tracks. The player will try not to exceed this target buffer. Only used when targetBufferBytes is LENGTH_UNSET.

Parameters
renderers: Array<Renderer!>!

The renderers for which the track were selected.

trackSelectionArray: Array<ExoTrackSelection!>!

The selected tracks.

Returns
Int

The target buffer size in bytes.