Java源码示例:com.google.android.exoplayer2.database.ExoDatabaseProvider
示例1
public void setUri(Uri uri) {
if (uri == null) {
return;
}
player.stop();
prepared = false;
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory("Aerial Dream");
DataSource.Factory dataSourceFactory = cacheSize > 0
? new CacheDataSourceFactory(new SimpleCache(getContext().getCacheDir(), new LeastRecentlyUsedCacheEvictor(cacheSize), new ExoDatabaseProvider(getContext())), httpDataSourceFactory, 0)
: httpDataSourceFactory;
mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri);
player.prepare(mediaSource);
}
示例2
@Provides
@Singleton
ExoCreator provideExoCreator() {
SimpleCache cache = new SimpleCache(new File(mApplication.getCacheDir(), "/toro_cache"),
new LeastRecentlyUsedCacheEvictor(200 * 1024 * 1024), new ExoDatabaseProvider(mApplication));
Config config = new Config.Builder(mApplication).setMediaSourceBuilder(MediaSourceBuilder.LOOPING).setCache(cache)
.build();
return ToroExo.with(mApplication).getCreator(config);
}
示例3
private Cache newCache() {
return new SimpleCache(
new File(mAppContext.getExternalCacheDir(), "exo-video-cache"),//缓存目录
new LeastRecentlyUsedCacheEvictor(512 * 1024 * 1024),//缓存大小,默认512M,使用LRU算法实现
new ExoDatabaseProvider(mAppContext));
}