BasePreloadManager


@UnstableApi
abstract class BasePreloadManager<T>

Known direct subclasses
DefaultPreloadManager

A preload manager that preloads with the PreloadMediaSource to load the media data into the SampleQueue.


A base implementation of a preload manager, which maintains the lifecycle of media sources.

Methods should be called on the same thread.

Summary

Nested types

protected abstract class BasePreloadManager.BuilderBase<T>

A base class of the builder of the concrete extension of BasePreloadManager.

Protected constructors

BasePreloadManager(
    rankingDataComparator: Comparator<T!>!,
    targetPreloadStatusControl: TargetPreloadStatusControl<T!>!,
    mediaSourceFactory: MediaSource.Factory!
)

Public functions

Unit
add(mediaItem: MediaItem!, rankingData: T!)

Adds a MediaItem with its rankingData to the preload manager.

Unit
add(mediaSource: MediaSource!, rankingData: T!)

Adds a MediaSource with its rankingData to the preload manager.

MediaSource?

Returns the MediaSource for the given MediaItem.

Int

Gets the count of the media sources currently being managed by the preload manager.

Unit

Invalidates the current preload progress, and triggers a new preload progress based on the new priorities of the managed media sources.

Unit

Releases the preload manager.

Boolean
remove(mediaItem: MediaItem!)

Removes a MediaItem from the preload manager.

Boolean
remove(mediaSource: MediaSource!)

Removes a MediaSource from the preload manager.

Protected functions

MediaSource!

Returns the MediaSource that the preload manager creates for preloading based on the given source.

TargetPreloadStatusControl.PreloadStatus?

Returns the target preload status of the given MediaSource.

Unit

Called when the given MediaSource completes to preload.

abstract Unit
preloadSourceInternal(mediaSource: MediaSource!, startPositionsUs: Long)

Preloads the given MediaSource.

Unit

Releases the preload manager, see release.

abstract Unit

Releases the given MediaSource.

Boolean

Returns whether the next MediaSource should start preloading.

Protected properties

Comparator<T!>!

Protected constructors

BasePreloadManager

protected BasePreloadManager(
    rankingDataComparator: Comparator<T!>!,
    targetPreloadStatusControl: TargetPreloadStatusControl<T!>!,
    mediaSourceFactory: MediaSource.Factory!
)

Public functions

add

fun add(mediaItem: MediaItem!, rankingData: T!): Unit

Adds a MediaItem with its rankingData to the preload manager.

Parameters
mediaItem: MediaItem!

The MediaItem to add.

rankingData: T!

The ranking data that is associated with the mediaItem.

add

fun add(mediaSource: MediaSource!, rankingData: T!): Unit

Adds a MediaSource with its rankingData to the preload manager.

Parameters
mediaSource: MediaSource!

The MediaSource to add.

rankingData: T!

The ranking data that is associated with the mediaSource.

getMediaSource

fun getMediaSource(mediaItem: MediaItem!): MediaSource?

Returns the MediaSource for the given MediaItem.

Parameters
mediaItem: MediaItem!

The media item.

Returns
MediaSource?

The source for the given mediaItem if it is managed by the preload manager, null otherwise.

getSourceCount

fun getSourceCount(): Int

Gets the count of the media sources currently being managed by the preload manager.

Returns
Int

The count of the media sources.

invalidate

fun invalidate(): Unit

Invalidates the current preload progress, and triggers a new preload progress based on the new priorities of the managed media sources.

release

fun release(): Unit

Releases the preload manager.

remove

fun remove(mediaItem: MediaItem!): Boolean

Removes a MediaItem from the preload manager.

Parameters
mediaItem: MediaItem!

The MediaItem to remove.

Returns
Boolean

true if the preload manager is holding a MediaSource of the given MediaItem and it has been removed, otherwise false.

remove

fun remove(mediaSource: MediaSource!): Boolean

Removes a MediaSource from the preload manager.

Parameters
mediaSource: MediaSource!

The MediaSource to remove.

Returns
Boolean

true if the preload manager is holding the given MediaSource instance and it has been removed, otherwise false.

Protected functions

createMediaSourceForPreloading

protected fun createMediaSourceForPreloading(mediaSource: MediaSource!): MediaSource!

Returns the MediaSource that the preload manager creates for preloading based on the given source. The default implementation returns the same source.

Parameters
mediaSource: MediaSource!

The source based on which the preload manager creates for preloading.

Returns
MediaSource!

The source the preload manager creates for preloading.

getTargetPreloadStatus

protected fun getTargetPreloadStatus(source: MediaSource!): TargetPreloadStatusControl.PreloadStatus?

Returns the target preload status of the given MediaSource.

onPreloadCompleted

protected fun onPreloadCompleted(source: MediaSource!): Unit

Called when the given MediaSource completes to preload.

preloadSourceInternal

protected abstract fun preloadSourceInternal(mediaSource: MediaSource!, startPositionsUs: Long): Unit

Preloads the given MediaSource.

Parameters
mediaSource: MediaSource!

The media source to preload.

startPositionsUs: Long

The expected starting position in microseconds, or TIME_UNSET to indicate the default start position.

releaseInternal

protected fun releaseInternal(): Unit

Releases the preload manager, see release.

releaseSourceInternal

protected abstract fun releaseSourceInternal(mediaSource: MediaSource!): Unit

Releases the given MediaSource.

Parameters
mediaSource: MediaSource!

The media source to release.

shouldStartPreloadingNextSource

protected fun shouldStartPreloadingNextSource(): Boolean

Returns whether the next MediaSource should start preloading.

Protected properties

rankingDataComparator

protected val rankingDataComparatorComparator<T!>!