use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.
the class HlsDownloaderTest method downloadEncMediaPlaylist.
@Test
public void downloadEncMediaPlaylist() throws Exception {
fakeDataSet = new FakeDataSet().setData(ENC_MEDIA_PLAYLIST_URI, ENC_MEDIA_PLAYLIST_DATA).setRandomData("enc.key", 8).setRandomData("enc2.key", 9).setRandomData("fileSequence0.ts", 10).setRandomData("fileSequence1.ts", 11).setRandomData("fileSequence2.ts", 12);
HlsDownloader downloader = getHlsDownloader(ENC_MEDIA_PLAYLIST_URI, getKeys());
downloader.download(progressListener);
assertCachedData(cache, fakeDataSet);
}
use of com.google.android.exoplayer2.upstream.cache.Cache in project NewPipe by TeamNewPipe.
the class CacheFactory method createDataSource.
@Override
public DataSource createDataSource() {
Log.d(TAG, "initExoPlayerCache: cacheDir = " + cacheDir.getAbsolutePath());
final DefaultDataSource dataSource = dataSourceFactory.createDataSource();
final FileDataSource fileSource = new FileDataSource();
final CacheDataSink dataSink = new CacheDataSink(cache, maxFileSize);
return new CacheDataSource(cache, dataSource, fileSource, dataSink, CACHE_FLAGS, null);
}
use of com.google.android.exoplayer2.upstream.cache.Cache in project Slide by ccrama.
the class ExoVideoView method setVideoURI.
/**
* Sets the player's URI and prepares for playback
*
* @param uri URI
* @param type Type of video
* @param listener EventLister attached to the player, helpful for player state
*/
public void setVideoURI(Uri uri, VideoType type, Player.Listener listener) {
// Create the data sources used to retrieve and cache the video
DataSource.Factory downloader = new OkHttpDataSource.Factory(Reddit.client).setUserAgent(context.getString(R.string.app_name));
DataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Reddit.videoCache).setUpstreamDataSourceFactory(downloader);
// Create an appropriate media source for the video type
MediaSource videoSource;
switch(type) {
// DASH video, e.g. v.redd.it video
case DASH:
videoSource = new DashMediaSource.Factory(cacheDataSourceFactory).createMediaSource(MediaItem.fromUri(uri));
break;
// Standard video, e.g. MP4 file
case STANDARD:
default:
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory).createMediaSource(MediaItem.fromUri(uri));
break;
}
player.setMediaSource(videoSource);
player.prepare();
if (listener != null) {
player.addListener(listener);
}
}
Aggregations