Java源码示例:com.google.android.exoplayer2.upstream.FileDataSourceFactory
示例1
private void enableCache(int maxCacheSizeMb) {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSizeMb * 1024 * 1024);
File file = new File(mContext.getCacheDir(), "media");
Log.d("ZAQ", "enableCache (" + maxCacheSizeMb + " MB), file: " + file.getAbsolutePath());
SimpleCache simpleCache = new SimpleCache(file, evictor);
mDataSourceFactory = new CacheDataSourceFactory(
simpleCache,
mDataSourceFactory,
new FileDataSourceFactory(),
new CacheDataSinkFactory(simpleCache, 2 * 1024 * 1024),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
new CacheDataSource.EventListener() {
@Override
public void onCacheIgnored(int reason) {
Log.d("ZAQ", "onCacheIgnored");
}
@Override
public void onCachedBytesRead(long cacheSizeBytes, long cachedBytesRead) {
Log.d("ZAQ", "onCachedBytesRead , cacheSizeBytes: " + cacheSizeBytes + " cachedBytesRead: " + cachedBytesRead);
}
});
}
示例2
public ExoPlayer2Helper(Context context) {
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
dataSourceFactory = new FileDataSourceFactory(this);
extractorsFactory = new DefaultExtractorsFactory();
DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter);
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context);
EventLogger eventLogger = new EventLogger(trackSelector);
player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector);
player.addListener(this);
player.addListener(eventLogger);
player.setAudioDebugListener(eventLogger);
player.setVideoDebugListener(eventLogger);
player.setMetadataOutput(eventLogger);
player.setVideoListener(this);
}
示例3
/** @see CacheDataSource#CacheDataSource(Cache, DataSource, int) */
public CacheDataSourceFactory(
Cache cache, DataSource.Factory upstreamFactory, @CacheDataSource.Flags int flags) {
this(
cache,
upstreamFactory,
new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE),
flags,
/* eventListener= */ null);
}
示例4
/** @see CacheDataSource#CacheDataSource(Cache, DataSource, int) */
public CacheDataSourceFactory(
Cache cache, DataSource.Factory upstreamFactory, @CacheDataSource.Flags int flags) {
this(
cache,
upstreamFactory,
new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE),
flags,
/* eventListener= */ null);
}
示例5
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory,
@CacheDataSource.Flags int flags, long maxCacheFileSize) {
this(cache, upstreamFactory, new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null);
}
示例6
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory,
@CacheDataSource.Flags int flags, long maxCacheFileSize) {
this(cache, upstreamFactory, new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null);
}
示例7
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory, int flags,
long maxCacheFileSize) {
this(cache, upstreamFactory, new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null);
}