public final class

CacheDataSource.Factory

extends java.lang.Object

implements DataSource.Factory

 java.lang.Object

↳androidx.media3.datasource.cache.CacheDataSource.Factory

Overview

for CacheDataSource instances.

Summary

Constructors
publicFactory()

Methods
public CacheDataSourcecreateDataSource()

public CacheDataSourcecreateDataSourceForDownloading()

Returns an instance suitable for downloading content.

public CacheDataSourcecreateDataSourceForRemovingDownload()

Returns an instance suitable for reading cached content as part of removing a download.

public CachegetCache()

Returns the cache that will be used, or null if CacheDataSource.Factory.setCache(Cache) has yet to be called.

public CacheKeyFactorygetCacheKeyFactory()

Returns the CacheKeyFactory that will be used.

public PriorityTaskManagergetUpstreamPriorityTaskManager()

Returns the PriorityTaskManager that will bs used when requesting data from upstream, or null if there is none.

public CacheDataSource.FactorysetCache(Cache cache)

Sets the cache that will be used.

public CacheDataSource.FactorysetCacheKeyFactory(CacheKeyFactory cacheKeyFactory)

Sets the CacheKeyFactory.

public CacheDataSource.FactorysetCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)

Sets the for DataSources for reading from the cache.

public CacheDataSource.FactorysetCacheWriteDataSinkFactory(DataSink.Factory cacheWriteDataSinkFactory)

Sets the for generating DataSinks for writing data to the cache.

public CacheDataSource.FactorysetEventListener(CacheDataSource.EventListener eventListener)

Sets the {link EventListener} to which events are delivered.

public CacheDataSource.FactorysetFlags(int flags)

Sets the CacheDataSource.Flags.

public CacheDataSource.FactorysetUpstreamDataSourceFactory(DataSource.Factory upstreamDataSourceFactory)

Sets the for upstream DataSources, which are used to read data in the case of a cache miss.

public CacheDataSource.FactorysetUpstreamPriority(int upstreamPriority)

Sets the to use when requesting data from upstream.

public CacheDataSource.FactorysetUpstreamPriorityTaskManager(PriorityTaskManager upstreamPriorityTaskManager)

Sets an optional PriorityTaskManager to use when requesting data from upstream.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Factory()

Methods

public CacheDataSource.Factory setCache(Cache cache)

Sets the cache that will be used.

Must be called before the factory is used.

Parameters:

cache: The cache that will be used.

Returns:

This factory.

public Cache getCache()

Returns the cache that will be used, or null if CacheDataSource.Factory.setCache(Cache) has yet to be called.

public CacheDataSource.Factory setCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)

Sets the for DataSources for reading from the cache.

The default is a in its default configuration.

Parameters:

cacheReadDataSourceFactory: The for reading from the cache.

Returns:

This factory.

public CacheDataSource.Factory setCacheWriteDataSinkFactory(DataSink.Factory cacheWriteDataSinkFactory)

Sets the for generating DataSinks for writing data to the cache. Passing null causes the cache to be read-only.

The default is a CacheDataSink.Factory in its default configuration.

Parameters:

cacheWriteDataSinkFactory: The for generating DataSinks for writing data to the cache, or null to disable writing.

Returns:

This factory.

public CacheDataSource.Factory setCacheKeyFactory(CacheKeyFactory cacheKeyFactory)

Sets the CacheKeyFactory.

The default is CacheKeyFactory.DEFAULT.

Parameters:

cacheKeyFactory: The CacheKeyFactory.

Returns:

This factory.

public CacheKeyFactory getCacheKeyFactory()

Returns the CacheKeyFactory that will be used.

public CacheDataSource.Factory setUpstreamDataSourceFactory(DataSource.Factory upstreamDataSourceFactory)

Sets the for upstream DataSources, which are used to read data in the case of a cache miss.

The default is null, and so this method must be called before the factory is used in order for data to be read from upstream in the case of a cache miss.

Parameters:

upstreamDataSourceFactory: The upstream DataSource for reading data not in the cache, or null to cause failure in the case of a cache miss.

Returns:

This factory.

public CacheDataSource.Factory setUpstreamPriorityTaskManager(PriorityTaskManager upstreamPriorityTaskManager)

Sets an optional PriorityTaskManager to use when requesting data from upstream.

If set, reads from the upstream DataSource will only be allowed to proceed if there are no higher priority tasks registered to the PriorityTaskManager. If there exists a higher priority task then will be thrown instead.

Note that requests to CacheDataSource instances are intended to be used as parts of (possibly larger) tasks that are registered with the PriorityTaskManager, and hence CacheDataSource does not register a task by itself. This must be done by the surrounding code that uses the CacheDataSource instances.

The default is null.

Parameters:

upstreamPriorityTaskManager: The upstream PriorityTaskManager.

Returns:

This factory.

public PriorityTaskManager getUpstreamPriorityTaskManager()

Returns the PriorityTaskManager that will bs used when requesting data from upstream, or null if there is none.

public CacheDataSource.Factory setUpstreamPriority(int upstreamPriority)

Sets the to use when requesting data from upstream. The priority is only used if a PriorityTaskManager is set by calling CacheDataSource.Factory.setUpstreamPriorityTaskManager(PriorityTaskManager).

The default is C.PRIORITY_PLAYBACK.

Parameters:

upstreamPriority: The to use when requesting data from upstream.

Returns:

This factory.

public CacheDataSource.Factory setFlags(int flags)

Sets the CacheDataSource.Flags.

The default is 0.

Parameters:

flags: The CacheDataSource.Flags.

Returns:

This factory.

public CacheDataSource.Factory setEventListener(CacheDataSource.EventListener eventListener)

Sets the {link EventListener} to which events are delivered.

The default is null.

Parameters:

eventListener: The CacheDataSource.EventListener.

Returns:

This factory.

public CacheDataSource createDataSource()

public CacheDataSource createDataSourceForDownloading()

Returns an instance suitable for downloading content. The created instance is equivalent to one that would be created by CacheDataSource.Factory.createDataSource(), except:

Returns:

An instance suitable for downloading content.

public CacheDataSource createDataSourceForRemovingDownload()

Returns an instance suitable for reading cached content as part of removing a download. The created instance is equivalent to one that would be created by CacheDataSource.Factory.createDataSource(), except:

Returns:

An instance suitable for reading cached content as part of removing a download.