BasePreloadManager


@UnstableApi
abstract class BasePreloadManager<T, PreloadStatusT>

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, PreloadStatusT>

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

A holder for information for preloading a single media source.

Protected constructors

BasePreloadManager(
    rankingDataComparator: RankingDataComparator<T!>!,
    targetPreloadStatusControl: TargetPreloadStatusControl<T!, PreloadStatusT!>!,
    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 PreloadManagerListener to listen to the preload events.

Unit
addMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    rankingDataList: (Mutable)List<T!>!
)

Adds a list of media items with their rankingData to the preload manager.

Unit
addMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    rankingDataList: (Mutable)List<T!>!
)

Adds a list of media sources with their rankingData to the preload manager.

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

Unit

Removes a list of media items from the preload manager.

Unit

Removes a list of media sources from the preload manager.

Unit

Resets the preload manager.

Protected functions

abstract BasePreloadManager.MediaSourceHolder!
createMediaSourceHolder(
    mediaItem: MediaItem!,
    mediaSource: MediaSource!,
    rankingData: T!
)

Returns the MediaSourceHolder that the preload manager creates for preloading based on the given MediaItem and MediaSource.

BasePreloadManager.MediaSourceHolder?
PreloadStatusT?
PreloadStatusT?
Unit
onCompleted(
    mediaItem: MediaItem!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
)

Called when the given MediaItem completes preloading.

Unit
onCompleted(
    mediaSource: MediaSource!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
)

Called when the given MediaSource completes preloading.

Unit
onError(
    error: PreloadException!,
    mediaItem: MediaItem!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
)

Called when an error occurs.

Unit
onError(
    error: PreloadException!,
    mediaSource: MediaSource!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
)

Called when an error occurs.

Unit
onMediaSourceUpdated(
    mediaItem: MediaItem!,
    updatedMediaSource: MediaSource!
)

Called when the given MediaItem has its corresponding MediaSource updated.

Unit
onSkipped(
    mediaSource: MediaSource!,
    shouldAdvancePredicate: Predicate<PreloadStatusT!>!
)

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

Unit

Called when there is a MediaSource has been cleared.

abstract Unit
preloadMediaSourceHolderInternal(
    mediaSourceHolder: BasePreloadManager.MediaSourceHolder!,
    targetPreloadStatus: PreloadStatusT!
)

Preloads the given MediaSourceHolder.

Unit

Releases the preload manager, see release.

Unit

Releases the given MediaSourceHolder.

Boolean

Returns whether the next MediaSource should start preloading.

Protected properties

RankingDataComparator<T!>!

Protected constructors

BasePreloadManager

protected BasePreloadManager(
    rankingDataComparator: RankingDataComparator<T!>!,
    targetPreloadStatusControl: TargetPreloadStatusControl<T!, PreloadStatusT!>!,
    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: PreloadManagerListener!): Unit

Adds a PreloadManagerListener to listen to the preload events.

This method can be called from any thread.

addMediaItems

fun addMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    rankingDataList: (Mutable)List<T!>!
): Unit

Adds a list of media items with their rankingData to the preload manager.

Parameters
mediaItems: (Mutable)List<MediaItem!>!

The media items to add.

rankingDataList: (Mutable)List<T!>!

The ranking data that are associated with each media item.

Throws
java.lang.IllegalArgumentException

If the passed mediaSources and rankingDataList are different in sizes.

addMediaSources

fun addMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    rankingDataList: (Mutable)List<T!>!
): Unit

Adds a list of media sources with their rankingData to the preload manager.

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The media sources to add.

rankingDataList: (Mutable)List<T!>!

The ranking data that are associated with each media source.

Throws
java.lang.IllegalArgumentException

If the passed mediaSources and rankingDataList are different in sizes.

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: PreloadManagerListener!): Unit

Removes a PreloadManagerListener.

Throws
java.lang.IllegalStateException

If this method is called from the wrong thread.

removeMediaItems

fun removeMediaItems(mediaItems: (Mutable)List<MediaItem!>!): Unit

Removes a list of media items from the preload manager.

Parameters
mediaItems: (Mutable)List<MediaItem!>!

The media items to remove.

removeMediaSources

fun removeMediaSources(mediaSources: (Mutable)List<MediaSource!>!): Unit

Removes a list of media sources from the preload manager.

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The media sources to remove.

reset

fun reset(): Unit

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

Protected functions

createMediaSourceHolder

protected abstract fun createMediaSourceHolder(
    mediaItem: MediaItem!,
    mediaSource: MediaSource!,
    rankingData: T!
): BasePreloadManager.MediaSourceHolder!

Returns the MediaSourceHolder that the preload manager creates for preloading based on the given MediaItem and MediaSource.

Parameters
mediaItem: MediaItem!

The MediaItem.

mediaSource: MediaSource!

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

rankingData: T!

The ranking data that is associated with the mediaItem.

Returns
BasePreloadManager.MediaSourceHolder!

The MediaSourceHolder the preload manager creates for preloading.

getMediaSourceHolderToClear

protected fun getMediaSourceHolderToClear(): BasePreloadManager.MediaSourceHolder?

getTargetPreloadStatusIfCurrentlyPreloading

protected fun getTargetPreloadStatusIfCurrentlyPreloading(mediaItem: MediaItem!): PreloadStatusT?

getTargetPreloadStatusIfCurrentlyPreloading

protected fun getTargetPreloadStatusIfCurrentlyPreloading(mediaSource: MediaSource!): PreloadStatusT?

onCompleted

protected fun onCompleted(
    mediaItem: MediaItem!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
): Unit

Called when the given MediaItem completes preloading.

onCompleted

protected fun onCompleted(
    mediaSource: MediaSource!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
): Unit

Called when the given MediaSource completes preloading.

onError

protected fun onError(
    error: PreloadException!,
    mediaItem: MediaItem!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
): Unit

Called when an error occurs.

onError

protected fun onError(
    error: PreloadException!,
    mediaSource: MediaSource!,
    shouldNotifyListenerAndAdvancePredicate: Predicate<PreloadStatusT!>!
): Unit

Called when an error occurs.

onMediaSourceUpdated

protected fun onMediaSourceUpdated(
    mediaItem: MediaItem!,
    updatedMediaSource: MediaSource!
): Unit

Called when the given MediaItem has its corresponding MediaSource updated.

Parameters
mediaItem: MediaItem!

The MediaItem that apps have added with.

updatedMediaSource: MediaSource!

The updated MediaSource.

onSkipped

protected fun onSkipped(
    mediaSource: MediaSource!,
    shouldAdvancePredicate: Predicate<PreloadStatusT!>!
): Unit

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

onSourceCleared

protected fun onSourceCleared(): Unit

Called when there is a MediaSource has been cleared.

preloadMediaSourceHolderInternal

protected abstract fun preloadMediaSourceHolderInternal(
    mediaSourceHolder: BasePreloadManager.MediaSourceHolder!,
    targetPreloadStatus: PreloadStatusT!
): Unit

Preloads the given MediaSourceHolder.

Parameters
mediaSourceHolder: BasePreloadManager.MediaSourceHolder!

The MediaSourceHolder to preload.

targetPreloadStatus: PreloadStatusT!

The target preload status.

releaseInternal

protected fun releaseInternal(): Unit

Releases the preload manager, see release.

releaseMediaSourceHolderInternal

@CallSuper
protected fun releaseMediaSourceHolderInternal(
    mediaSourceHolder: BasePreloadManager.MediaSourceHolder!
): Unit

Releases the given MediaSourceHolder.

Parameters
mediaSourceHolder: BasePreloadManager.MediaSourceHolder!

The MediaSourceHolder to remove.

shouldStartPreloadingNextSource

protected fun shouldStartPreloadingNextSource(): Boolean

Returns whether the next MediaSource should start preloading.

Protected properties

rankingDataComparator

protected val rankingDataComparatorRankingDataComparator<T!>!