本文整理汇总了Java中com.google.android.exoplayer2.upstream.FileDataSource类的典型用法代码示例。如果您正苦于以下问题:Java FileDataSource类的具体用法?Java FileDataSource怎么用?Java FileDataSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileDataSource类属于com.google.android.exoplayer2.upstream包,在下文中一共展示了FileDataSource类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
/**
* Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read
* data from the cache.
*/
public CacheDataSource buildCacheDataSource(boolean offline) {
DataSource cacheReadDataSource = cacheReadDataSourceFactory != null
? cacheReadDataSourceFactory.createDataSource() : new FileDataSource();
if (offline) {
return new CacheDataSource(cache, DummyDataSource.INSTANCE,
cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
} else {
DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null
? cacheWriteDataSinkFactory.createDataSink()
: new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
DataSource upstream = upstreamDataSourceFactory.createDataSource();
upstream = priorityTaskManager == null ? upstream
: new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD);
return new CacheDataSource(cache, upstream, cacheReadDataSource,
cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
}
}
示例2: buildCacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
private static CacheDataSource buildCacheDataSource(Context context, DataSource upstreamSource,
boolean useAesEncryption) throws CacheException {
File cacheDir = context.getExternalCacheDir();
Cache cache = new SimpleCache(new File(cacheDir, EXO_CACHE_DIR), new NoOpCacheEvictor());
emptyCache(cache);
// Source and cipher
final String secretKey = "testKey:12345678";
DataSource file = new FileDataSource();
DataSource cacheReadDataSource = useAesEncryption
? new AesCipherDataSource(Util.getUtf8Bytes(secretKey), file) : file;
// Sink and cipher
CacheDataSink cacheSink = new CacheDataSink(cache, EXO_CACHE_MAX_FILESIZE);
byte[] scratch = new byte[3897];
DataSink cacheWriteDataSink = useAesEncryption
? new AesCipherDataSink(Util.getUtf8Bytes(secretKey), cacheSink, scratch) : cacheSink;
return new CacheDataSource(cache,
upstreamSource,
cacheReadDataSource,
cacheWriteDataSink,
CacheDataSource.FLAG_BLOCK_ON_CACHE,
null); // eventListener
}
示例3: createCacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
private CacheDataSource createCacheDataSource(boolean setReadException,
boolean simulateUnknownLength, @CacheDataSource.Flags int flags,
CacheDataSink cacheWriteDataSink) {
FakeDataSource upstream = new FakeDataSource();
FakeData fakeData = upstream.getDataSet().newDefaultData()
.setSimulateUnknownLength(simulateUnknownLength).appendReadData(TEST_DATA);
if (setReadException) {
fakeData.appendReadError(new IOException("Shouldn't read from upstream"));
}
return new CacheDataSource(cache, upstream, new FileDataSource(), cacheWriteDataSink,
flags, null);
}
示例4: createDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
@Override
public DataSource createDataSource() {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
SimpleCache simpleCache =
new SimpleCache(new File(context.getCacheDir(), "media"), evictor);
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
null);
}
示例5: createDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
@Override
public DataSource createDataSource() {
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
new FileDataSource(), new CacheDataSink(simpleCache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE),
0, listener);
}
示例6: initPlayer
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
private void initPlayer(String url) {
// 1.创建一个默认TrackSelector,测量播放过程中的带宽。 如果不需要,可以为null。
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
//从MediaSource中选出media提供给可用的Render S来渲染,在创建播放器时被注入
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
// 2.创建一个默认的LoadControl
//Create a default LoadControl 控制MediaSource缓存media
DefaultLoadControl loadControl = new DefaultLoadControl();
// BufferingLoadControl bufferingLoadControl = new BufferingLoadControl();
//生成加载媒体数据的DataSource实例。
// dataSourceFactory = new DefaultDataSourceFactory(this,
// Util.getUserAgent(this, "aitrip"), bandwidthMeter);
//自定义解密工厂
aitripFactory = new AitripDataSourceFactory(this,
Util.getUserAgent(this, "aitrip"), bandwidthMeter);
extractorsFactory = new DefaultExtractorsFactory();
// factory = new DiyExtractorsFactory();
FileDataSource fileDataSource = new FileDataSource();
//test mp3
// url = "https://storage.googleapis.com/exoplayer-test-media-0/play.mp3";
// MediaSource代表要播放的媒体。
videoSource = new ExtractorMediaSource(Uri.parse(url),
aitripFactory, extractorsFactory, null, null);
// 3.创建播放器
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
//SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player);
//设置监听器
player.addListener(eventListener);
//装载多个资源
MediaSource[] mediaSources = new MediaSource[1];
// mediaSources[0] = buildMediaSource(Uri.parse(huai), "");
// mediaSources[1] = buildMediaSource(Uri.parse(deng), "");
mediaSources[0] = buildMediaSource(Uri.parse(deng), "");
// mediaSources[2] = buildMediaSource(playerUri, "");
// mediaSources[3] = buildMediaSource(Uri.parse(deng), "");
ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(mediaSources);
//设置资源
player.prepare(mediaSource);
window = new Timeline.Window();
}
示例7: CacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
/**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache. The sink is configured to fragment data such that no single
* cache file is greater than maxCacheFileSize bytes.
*
* @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
* and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size
* exceeds this value, then the data will be fragmented into multiple cache files. The
* finer-grained this is the finer-grained the eviction policy can be.
*/
public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags,
long maxCacheFileSize) {
this(cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize),
flags, null);
}
示例8: CacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
/**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache. The sink is configured to fragment data such that no single
* cache file is greater than maxCacheFileSize bytes.
*
* @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE} and {@link
* #FLAG_IGNORE_CACHE_ON_ERROR} or 0.
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size
* exceeds this value, then the data will be fragmented into multiple cache files. The
* finer-grained this is the finer-grained the eviction policy can be.
*/
public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags,
long maxCacheFileSize) {
this(cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize),
flags, null);
}
示例9: CacheDataSource
import com.google.android.exoplayer2.upstream.FileDataSource; //导入依赖的package包/类
/**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache. The sink is configured to fragment data such that no single
* cache file is greater than maxCacheFileSize bytes.
*
* @param cache The cache.
* @param upstream A {@link DataSource} for reading data not in the cache.
* @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
* and {@link #FLAG_CACHE_UNBOUNDED_REQUESTS} or 0.
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size
* exceeds this value, then the data will be fragmented into multiple cache files. The
* finer-grained this is the finer-grained the eviction policy can be.
*/
public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags,
long maxCacheFileSize) {
this(cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize),
flags, null);
}