BasePreloadManager
@UnstableApi
public abstract class BasePreloadManager<T, PreloadStatusT>
DefaultPreloadManager |
A preload manager that preloads with the |
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 |
protected inner class BasePreloadManager.MediaSourceHolder implements ComparableA holder for information for preloading a single media source. |
Protected fields |
|
|---|---|
final RankingDataComparator<T> |
Protected constructors |
|---|
BasePreloadManager( |
Public methods |
|
|---|---|
final void |
Adds a |
final void |
add(MediaSource mediaSource, T rankingData)Adds a |
void |
addListener(PreloadManagerListener listener)Adds a |
final void |
addMediaItems(List<MediaItem> mediaItems, List<T> rankingDataList)Adds a list of |
final void |
addMediaSources(Adds a list of |
void |
Clears all the |
final @Nullable MediaSource |
getMediaSource(MediaItem mediaItem)Returns the |
final int |
Gets the count of the |
final void |
Invalidates the current preload progress, and triggers a new preload progress based on the new priorities of the managed |
final void |
release()Releases the preload manager. |
final boolean |
Removes a |
final boolean |
remove(MediaSource mediaSource)Removes a |
void |
removeListener(PreloadManagerListener listener)Removes a |
final void |
removeMediaItems(List<MediaItem> mediaItems)Removes a list of |
final void |
removeMediaSources(List<MediaSource> mediaSources)Removes a list of |
final void |
reset()Resets the preload manager. |
Protected methods |
|
|---|---|
abstract BasePreloadManager.MediaSourceHolder |
createMediaSourceHolder(Returns the |
@Nullable BasePreloadManager.MediaSourceHolder |
|
final @Nullable PreloadStatusT |
|
final @Nullable PreloadStatusT |
getTargetPreloadStatusIfCurrentlyPreloading(MediaSource mediaSource) |
final void |
onCompleted(Called when the given |
final void |
onCompleted(Called when the given |
final void |
onError(Called when an error occurs. |
final void |
onError(Called when an error occurs. |
final void |
onMediaSourceUpdated(Called when the given |
final void |
onSkipped(Called when the given |
final void |
Called when there is a |
abstract void |
preloadMediaSourceHolderInternal(Preloads the given |
void |
Releases the preload manager, see |
void |
@CallSuperReleases the given |
boolean |
Returns whether the next |
Protected fields
Protected constructors
BasePreloadManager
protected BasePreloadManager(
RankingDataComparator<T> rankingDataComparator,
TargetPreloadStatusControl<T, PreloadStatusT> 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.
add
public final void add(MediaSource mediaSource, T rankingData)
Adds a MediaSource with its rankingData to the preload manager.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
T rankingData |
The ranking data that is associated with the |
addListener
public void addListener(PreloadManagerListener listener)
Adds a PreloadManagerListener to listen to the preload events.
This method can be called from any thread.
addMediaItems
public final void addMediaItems(List<MediaItem> mediaItems, List<T> rankingDataList)
Adds a list of media items with their rankingData to the preload manager.
| Parameters | |
|---|---|
List<MediaItem> mediaItems |
The |
List<T> rankingDataList |
The ranking data that are associated with each media item. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the passed |
addMediaSources
public final void addMediaSources(
List<MediaSource> mediaSources,
List<T> rankingDataList
)
Adds a list of media sources with their rankingData to the preload manager.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The |
List<T> rankingDataList |
The ranking data that are associated with each media source. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the passed |
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 |
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 |
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.
| Returns | |
|---|---|
boolean |
|
remove
public final boolean remove(MediaSource mediaSource)
Removes a MediaSource from the preload manager.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
| Returns | |
|---|---|
boolean |
|
removeListener
public void removeListener(PreloadManagerListener listener)
Removes a PreloadManagerListener.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If this method is called from the wrong thread. |
removeMediaItems
public final void removeMediaItems(List<MediaItem> mediaItems)
Removes a list of media items from the preload manager.
| Parameters | |
|---|---|
List<MediaItem> mediaItems |
The |
removeMediaSources
public final void removeMediaSources(List<MediaSource> mediaSources)
Removes a list of media sources from the preload manager.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The |
reset
public final void reset()
Resets the preload manager. All sources that the preload manager is holding will be released.
Protected methods
createMediaSourceHolder
protected abstract BasePreloadManager.MediaSourceHolder createMediaSourceHolder(
MediaItem mediaItem,
MediaSource mediaSource,
T rankingData
)
Returns the MediaSourceHolder that the preload manager creates for preloading based on the given MediaItem and MediaSource.
| Parameters | |
|---|---|
MediaItem mediaItem |
The |
MediaSource mediaSource |
The |
T rankingData |
The ranking data that is associated with the |
| Returns | |
|---|---|
BasePreloadManager.MediaSourceHolder |
The |
getMediaSourceHolderToClear
protected @Nullable BasePreloadManager.MediaSourceHolder getMediaSourceHolderToClear()
getTargetPreloadStatusIfCurrentlyPreloading
protected final @Nullable PreloadStatusT getTargetPreloadStatusIfCurrentlyPreloading(MediaItem mediaItem)
getTargetPreloadStatusIfCurrentlyPreloading
protected final @Nullable PreloadStatusT getTargetPreloadStatusIfCurrentlyPreloading(MediaSource mediaSource)
onCompleted
protected final void onCompleted(
MediaItem mediaItem,
Predicate<PreloadStatusT> shouldNotifyListenerAndAdvancePredicate
)
Called when the given MediaItem completes preloading.
onCompleted
protected final void onCompleted(
MediaSource mediaSource,
Predicate<PreloadStatusT> shouldNotifyListenerAndAdvancePredicate
)
Called when the given MediaSource completes preloading.
onError
protected final void onError(
PreloadException error,
MediaItem mediaItem,
Predicate<PreloadStatusT> shouldNotifyListenerAndAdvancePredicate
)
Called when an error occurs.
onError
protected final void onError(
PreloadException error,
MediaSource mediaSource,
Predicate<PreloadStatusT> shouldNotifyListenerAndAdvancePredicate
)
Called when an error occurs.
onMediaSourceUpdated
protected final void onMediaSourceUpdated(
MediaItem mediaItem,
MediaSource updatedMediaSource
)
Called when the given MediaItem has its corresponding MediaSource updated.
| Parameters | |
|---|---|
MediaItem mediaItem |
The |
MediaSource updatedMediaSource |
The updated |
onSkipped
protected final void onSkipped(
MediaSource mediaSource,
Predicate<PreloadStatusT> shouldAdvancePredicate
)
Called when the given MediaSource has been skipped before completing preloading.
onSourceCleared
protected final void onSourceCleared()
Called when there is a MediaSource has been cleared.
preloadMediaSourceHolderInternal
protected abstract void preloadMediaSourceHolderInternal(
BasePreloadManager.MediaSourceHolder mediaSourceHolder,
PreloadStatusT targetPreloadStatus
)
Preloads the given MediaSourceHolder.
| Parameters | |
|---|---|
BasePreloadManager.MediaSourceHolder mediaSourceHolder |
The |
PreloadStatusT targetPreloadStatus |
The target preload status. |
releaseMediaSourceHolderInternal
@CallSuper
protected void releaseMediaSourceHolderInternal(
BasePreloadManager.MediaSourceHolder mediaSourceHolder
)
Releases the given MediaSourceHolder.
| Parameters | |
|---|---|
BasePreloadManager.MediaSourceHolder mediaSourceHolder |
The |
shouldStartPreloadingNextSource
protected boolean shouldStartPreloadingNextSource()
Returns whether the next MediaSource should start preloading.