Class CacheDataSource.Factory
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.cache.CacheDataSource.Factory
-
- All Implemented Interfaces:
DataSource.Factory
- Enclosing class:
- CacheDataSource
public static final class CacheDataSource.Factory extends Object implements DataSource.Factory
DataSource.FactoryforCacheDataSourceinstances.
-
-
Constructor Summary
Constructors Constructor Description Factory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheDataSourcecreateDataSource()Creates aDataSourceinstance.CacheDataSourcecreateDataSourceForDownloading()Returns an instance suitable for downloading content.CacheDataSourcecreateDataSourceForRemovingDownload()Returns an instance suitable for reading cached content as part of removing a download.CachegetCache()Returns the cache that will be used, ornullifsetCache(com.google.android.exoplayer2.upstream.cache.Cache)has yet to be called.CacheKeyFactorygetCacheKeyFactory()Returns theCacheKeyFactorythat will be used.PriorityTaskManagergetUpstreamPriorityTaskManager()Returns thePriorityTaskManagerthat will bs used when requesting data from upstream, ornullif there is none.CacheDataSource.FactorysetCache(Cache cache)Sets the cache that will be used.CacheDataSource.FactorysetCacheKeyFactory(CacheKeyFactory cacheKeyFactory)Sets theCacheKeyFactory.CacheDataSource.FactorysetCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)Sets theDataSource.FactoryforDataSourcesfor reading from the cache.CacheDataSource.FactorysetCacheWriteDataSinkFactory(DataSink.Factory cacheWriteDataSinkFactory)Sets theDataSink.Factoryfor generatingDataSinksfor writing data to the cache.CacheDataSource.FactorysetEventListener(CacheDataSource.EventListener eventListener)Sets the {link EventListener} to which events are delivered.CacheDataSource.FactorysetFlags(@com.google.android.exoplayer2.upstream.cache.CacheDataSource.Flags int flags)Sets theCacheDataSource.Flags.CacheDataSource.FactorysetUpstreamDataSourceFactory(DataSource.Factory upstreamDataSourceFactory)Sets theDataSource.Factoryfor upstreamDataSources, which are used to read data in the case of a cache miss.CacheDataSource.FactorysetUpstreamPriority(int upstreamPriority)Sets the priority to use when requesting data from upstream.CacheDataSource.FactorysetUpstreamPriorityTaskManager(PriorityTaskManager upstreamPriorityTaskManager)Sets an optionalPriorityTaskManagerto use when requesting data from upstream.
-
-
-
Method Detail
-
setCache
@CanIgnoreReturnValue 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.
-
getCache
@Nullable public Cache getCache()
Returns the cache that will be used, ornullifsetCache(com.google.android.exoplayer2.upstream.cache.Cache)has yet to be called.
-
setCacheReadDataSourceFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)
Sets theDataSource.FactoryforDataSourcesfor reading from the cache.The default is a
FileDataSource.Factoryin its default configuration.- Parameters:
cacheReadDataSourceFactory- TheDataSource.Factoryfor reading from the cache.- Returns:
- This factory.
-
setCacheWriteDataSinkFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setCacheWriteDataSinkFactory(@Nullable DataSink.Factory cacheWriteDataSinkFactory)
Sets theDataSink.Factoryfor generatingDataSinksfor writing data to the cache. Passingnullcauses the cache to be read-only.The default is a
CacheDataSink.Factoryin its default configuration.- Parameters:
cacheWriteDataSinkFactory- TheDataSink.Factoryfor generatingDataSinksfor writing data to the cache, ornullto disable writing.- Returns:
- This factory.
-
setCacheKeyFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setCacheKeyFactory(CacheKeyFactory cacheKeyFactory)
Sets theCacheKeyFactory.The default is
CacheKeyFactory.DEFAULT.- Parameters:
cacheKeyFactory- TheCacheKeyFactory.- Returns:
- This factory.
-
getCacheKeyFactory
public CacheKeyFactory getCacheKeyFactory()
Returns theCacheKeyFactorythat will be used.
-
setUpstreamDataSourceFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setUpstreamDataSourceFactory(@Nullable DataSource.Factory upstreamDataSourceFactory)
Sets theDataSource.Factoryfor upstreamDataSources, 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 upstreamDataSourcefor reading data not in the cache, ornullto cause failure in the case of a cache miss.- Returns:
- This factory.
-
setUpstreamPriorityTaskManager
@CanIgnoreReturnValue public CacheDataSource.Factory setUpstreamPriorityTaskManager(@Nullable PriorityTaskManager upstreamPriorityTaskManager)
Sets an optionalPriorityTaskManagerto use when requesting data from upstream.If set, reads from the upstream
DataSourcewill only be allowed to proceed if there are no higher priority tasks registered to thePriorityTaskManager. If there exists a higher priority task thenPriorityTaskManager.PriorityTooLowExceptionwill be thrown instead.Note that requests to
CacheDataSourceinstances are intended to be used as parts of (possibly larger) tasks that are registered with thePriorityTaskManager, and henceCacheDataSourcedoes not register a task by itself. This must be done by the surrounding code that uses theCacheDataSourceinstances.The default is
null.- Parameters:
upstreamPriorityTaskManager- The upstreamPriorityTaskManager.- Returns:
- This factory.
-
getUpstreamPriorityTaskManager
@Nullable public PriorityTaskManager getUpstreamPriorityTaskManager()
Returns thePriorityTaskManagerthat will bs used when requesting data from upstream, ornullif there is none.
-
setUpstreamPriority
@CanIgnoreReturnValue public CacheDataSource.Factory setUpstreamPriority(int upstreamPriority)
Sets the priority to use when requesting data from upstream. The priority is only used if aPriorityTaskManageris set by callingsetUpstreamPriorityTaskManager(com.google.android.exoplayer2.util.PriorityTaskManager).The default is
C.PRIORITY_PLAYBACK.- Parameters:
upstreamPriority- The priority to use when requesting data from upstream.- Returns:
- This factory.
-
setFlags
@CanIgnoreReturnValue public CacheDataSource.Factory setFlags(@com.google.android.exoplayer2.upstream.cache.CacheDataSource.Flags int flags)
Sets theCacheDataSource.Flags.The default is
0.- Parameters:
flags- TheCacheDataSource.Flags.- Returns:
- This factory.
-
setEventListener
@CanIgnoreReturnValue public CacheDataSource.Factory setEventListener(@Nullable CacheDataSource.EventListener eventListener)
Sets the {link EventListener} to which events are delivered.The default is
null.- Parameters:
eventListener- TheCacheDataSource.EventListener.- Returns:
- This factory.
-
createDataSource
public CacheDataSource createDataSource()
Description copied from interface:DataSource.FactoryCreates aDataSourceinstance.- Specified by:
createDataSourcein interfaceDataSource.Factory
-
createDataSourceForDownloading
public CacheDataSource createDataSourceForDownloading()
Returns an instance suitable for downloading content. The created instance is equivalent to one that would be created bycreateDataSource(), except:- The
CacheDataSource.FLAG_BLOCK_ON_CACHEis always set. - The task priority is overridden to be
C.PRIORITY_DOWNLOAD.
- Returns:
- An instance suitable for downloading content.
- The
-
createDataSourceForRemovingDownload
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 bycreateDataSource(), except:- The upstream is overridden to be
null, since when removing content we don't want to request anything that's not already cached. - The
CacheDataSource.FLAG_BLOCK_ON_CACHEis always set. - The task priority is overridden to be
C.PRIORITY_DOWNLOAD.
- Returns:
- An instance suitable for reading cached content as part of removing a download.
- The upstream is overridden to be
-
-