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.Factory
forCacheDataSource
instances.
-
-
Constructor Summary
Constructors Constructor Description Factory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheDataSource
createDataSource()
Creates aDataSource
instance.CacheDataSource
createDataSourceForDownloading()
Returns an instance suitable for downloading content.CacheDataSource
createDataSourceForRemovingDownload()
Returns an instance suitable for reading cached content as part of removing a download.Cache
getCache()
Returns the cache that will be used, ornull
ifsetCache(com.google.android.exoplayer2.upstream.cache.Cache)
has yet to be called.CacheKeyFactory
getCacheKeyFactory()
Returns theCacheKeyFactory
that will be used.PriorityTaskManager
getUpstreamPriorityTaskManager()
Returns thePriorityTaskManager
that will bs used when requesting data from upstream, ornull
if there is none.CacheDataSource.Factory
setCache(Cache cache)
Sets the cache that will be used.CacheDataSource.Factory
setCacheKeyFactory(CacheKeyFactory cacheKeyFactory)
Sets theCacheKeyFactory
.CacheDataSource.Factory
setCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)
Sets theDataSource.Factory
forDataSources
for reading from the cache.CacheDataSource.Factory
setCacheWriteDataSinkFactory(DataSink.Factory cacheWriteDataSinkFactory)
Sets theDataSink.Factory
for generatingDataSinks
for writing data to the cache.CacheDataSource.Factory
setEventListener(CacheDataSource.EventListener eventListener)
Sets the {link EventListener} to which events are delivered.CacheDataSource.Factory
setFlags(@com.google.android.exoplayer2.upstream.cache.CacheDataSource.Flags int flags)
Sets theCacheDataSource.Flags
.CacheDataSource.Factory
setUpstreamDataSourceFactory(DataSource.Factory upstreamDataSourceFactory)
Sets theDataSource.Factory
for upstreamDataSources
, which are used to read data in the case of a cache miss.CacheDataSource.Factory
setUpstreamPriority(int upstreamPriority)
Sets the priority to use when requesting data from upstream.CacheDataSource.Factory
setUpstreamPriorityTaskManager(PriorityTaskManager upstreamPriorityTaskManager)
Sets an optionalPriorityTaskManager
to 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, ornull
ifsetCache(com.google.android.exoplayer2.upstream.cache.Cache)
has yet to be called.
-
setCacheReadDataSourceFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setCacheReadDataSourceFactory(DataSource.Factory cacheReadDataSourceFactory)
Sets theDataSource.Factory
forDataSources
for reading from the cache.The default is a
FileDataSource.Factory
in its default configuration.- Parameters:
cacheReadDataSourceFactory
- TheDataSource.Factory
for reading from the cache.- Returns:
- This factory.
-
setCacheWriteDataSinkFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setCacheWriteDataSinkFactory(@Nullable DataSink.Factory cacheWriteDataSinkFactory)
Sets theDataSink.Factory
for generatingDataSinks
for writing data to the cache. Passingnull
causes the cache to be read-only.The default is a
CacheDataSink.Factory
in its default configuration.- Parameters:
cacheWriteDataSinkFactory
- TheDataSink.Factory
for generatingDataSinks
for writing data to the cache, ornull
to 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 theCacheKeyFactory
that will be used.
-
setUpstreamDataSourceFactory
@CanIgnoreReturnValue public CacheDataSource.Factory setUpstreamDataSourceFactory(@Nullable DataSource.Factory upstreamDataSourceFactory)
Sets theDataSource.Factory
for 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 upstreamDataSource
for reading data not in the cache, ornull
to cause failure in the case of a cache miss.- Returns:
- This factory.
-
setUpstreamPriorityTaskManager
@CanIgnoreReturnValue public CacheDataSource.Factory setUpstreamPriorityTaskManager(@Nullable PriorityTaskManager upstreamPriorityTaskManager)
Sets an optionalPriorityTaskManager
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 thePriorityTaskManager
. If there exists a higher priority task thenPriorityTaskManager.PriorityTooLowException
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 thePriorityTaskManager
, and henceCacheDataSource
does not register a task by itself. This must be done by the surrounding code that uses theCacheDataSource
instances.The default is
null
.- Parameters:
upstreamPriorityTaskManager
- The upstreamPriorityTaskManager
.- Returns:
- This factory.
-
getUpstreamPriorityTaskManager
@Nullable public PriorityTaskManager getUpstreamPriorityTaskManager()
Returns thePriorityTaskManager
that will bs used when requesting data from upstream, ornull
if 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 aPriorityTaskManager
is 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.Factory
Creates aDataSource
instance.- Specified by:
createDataSource
in 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_CACHE
is 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_CACHE
is 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
-
-