BasePreloadManager


@UnstableApi
public 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 fields

final Comparator<T>

Protected constructors

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

Public methods

final void
add(MediaItem mediaItem, T rankingData)

Adds a MediaItem with its rankingData to the preload manager.

final void
add(MediaSource mediaSource, T rankingData)

Adds a MediaSource with its rankingData to the preload manager.

final @Nullable MediaSource

Returns the MediaSource for the given MediaItem.

final int

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

final void

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

final void

Releases the preload manager.

final boolean
remove(MediaItem mediaItem)

Removes a MediaItem from the preload manager.

final boolean
remove(MediaSource mediaSource)

Removes a MediaSource from the preload manager.

Protected methods

MediaSource

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

final @Nullable TargetPreloadStatusControl.PreloadStatus

Returns the target preload status of the given MediaSource.

final void

Called when the given MediaSource completes to preload.

abstract void
preloadSourceInternal(MediaSource mediaSource, long startPositionsUs)

Preloads the given MediaSource.

void

Releases the preload manager, see release.

abstract void

Releases the given MediaSource.

boolean

Returns whether the next MediaSource should start preloading.

Protected fields

rankingDataComparator

protected final Comparator<T> rankingDataComparator

Protected constructors

BasePreloadManager

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

Public methods

add

public final void add(MediaItem mediaItem, T rankingData)

Adds a MediaItem with its rankingData to the preload manager.

Parameters
MediaItem mediaItem

The MediaItem to add.

T rankingData

The ranking data that is associated with the mediaItem.

add

public final void add(MediaSource mediaSource, T rankingData)

Adds a MediaSource with its rankingData to the preload manager.

Parameters
MediaSource mediaSource

The MediaSource to add.

T rankingData

The ranking data that is associated with the mediaSource.

getMediaSource

public final @Nullable MediaSource getMediaSource(MediaItem mediaItem)

Returns the MediaSource for the given MediaItem.

Parameters
MediaItem mediaItem

The media item.

Returns
@Nullable MediaSource

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

getSourceCount

public final int getSourceCount()

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

Returns
int

The count of the media sources.

invalidate

public final void invalidate()

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

release

public final void release()

Releases the preload manager.

remove

public final boolean remove(MediaItem mediaItem)

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

public final boolean remove(MediaSource mediaSource)

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 methods

createMediaSourceForPreloading

protected MediaSource createMediaSourceForPreloading(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 final @Nullable TargetPreloadStatusControl.PreloadStatus getTargetPreloadStatus(MediaSource source)

Returns the target preload status of the given MediaSource.

onPreloadCompleted

protected final void onPreloadCompleted(MediaSource source)

Called when the given MediaSource completes to preload.

preloadSourceInternal

protected abstract void preloadSourceInternal(MediaSource mediaSource, long startPositionsUs)

Preloads the given MediaSource.

Parameters
MediaSource mediaSource

The media source to preload.

long startPositionsUs

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

releaseInternal

protected void releaseInternal()

Releases the preload manager, see release.

releaseSourceInternal

protected abstract void releaseSourceInternal(MediaSource mediaSource)

Releases the given MediaSource.

Parameters
MediaSource mediaSource

The media source to release.

shouldStartPreloadingNextSource

protected boolean shouldStartPreloadingNextSource()

Returns whether the next MediaSource should start preloading.