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.

Listener for events in a preload manager.

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.

Unit

Adds a Listener to listen to the preload events.

Unit

Clears all the listeners.

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.

Unit

Removes a Listener.

Unit

Resets the preload manager.

Protected functions

abstract Unit

Clears the preloaded data of the given MediaSource, while not releasing the instance of it.

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 preloading.

Unit

Called when an error occurs.

Unit

Called when the given MediaSource has been skipped before completing preloading.

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.

addListener

fun addListener(listener: BasePreloadManager.Listener!): Unit

Adds a Listener to listen to the preload events.

This method can be called from any thread.

clearListeners

fun clearListeners(): Unit

Clears all the listeners.

Throws
java.lang.IllegalStateException

If this method is called from the wrong thread.

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.

The preload manager must not be used after calling this method.

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.

removeListener

fun removeListener(listener: BasePreloadManager.Listener!): Unit

Removes a Listener.

Throws
java.lang.IllegalStateException

If this method is called from the wrong thread.

reset

fun reset(): Unit

Resets the preload manager. All sources that the preload manager is holding will be released.

Protected functions

clearSourceInternal

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

Clears the preloaded data of the given MediaSource, while not releasing the instance of it.

Parameters
mediaSource: MediaSource!

The media source to clear.

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 preloading.

onPreloadError

protected fun onPreloadError(error: PreloadException!, source: MediaSource!): Unit

Called when an error occurs.

onPreloadSkipped

protected fun onPreloadSkipped(source: MediaSource!): Unit

Called when the given MediaSource has been skipped before completing preloading.

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!>!