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.

Listener for events in a preload manager.

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.

void

Adds a Listener to listen to the preload events.

void

Clears all the listeners.

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.

void

Removes a Listener.

final void

Resets the preload manager.

Protected methods

abstract void

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.

final @Nullable TargetPreloadStatusControl.PreloadStatus

Returns the target preload status of the given MediaSource.

final void

Called when the given MediaSource completes preloading.

final void

Called when an error occurs.

final void

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

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.

addListener

public void addListener(BasePreloadManager.Listener listener)

Adds a Listener to listen to the preload events.

This method can be called from any thread.

clearListeners

public void clearListeners()

Clears all the listeners.

Throws
java.lang.IllegalStateException

If this method is called from the wrong thread.

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.

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

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.

removeListener

public void removeListener(BasePreloadManager.Listener listener)

Removes a Listener.

Throws
java.lang.IllegalStateException

If this method is called from the wrong thread.

reset

public final void reset()

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

Protected methods

clearSourceInternal

protected abstract void clearSourceInternal(MediaSource mediaSource)

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

onPreloadError

protected final void onPreloadError(PreloadException error, MediaSource source)

Called when an error occurs.

onPreloadSkipped

protected final void onPreloadSkipped(MediaSource source)

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

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.