use of com.google.android.exoplayer2.offline.Downloader in project ExoPlayer by google.
the class SsDownloaderTest method createWithDefaultDownloaderFactory.
@Test
public void createWithDefaultDownloaderFactory() throws Exception {
CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
Runnable::run);
Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
"id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_SS).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
0, /* trackIndex= */
0))).build());
assertThat(downloader).isInstanceOf(SsDownloader.class);
}
use of com.google.android.exoplayer2.offline.Downloader in project ExoPlayer by google.
the class DefaultDownloaderFactory method createDownloader.
private Downloader createDownloader(DownloadRequest request, @C.ContentType int contentType) {
@Nullable Constructor<? extends Downloader> constructor = CONSTRUCTORS.get(contentType);
if (constructor == null) {
throw new IllegalStateException("Module missing for content type " + contentType);
}
MediaItem mediaItem = new MediaItem.Builder().setUri(request.uri).setStreamKeys(request.streamKeys).setCustomCacheKey(request.customCacheKey).build();
try {
return constructor.newInstance(mediaItem, cacheDataSourceFactory, executor);
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate downloader for content type " + contentType);
}
}
use of com.google.android.exoplayer2.offline.Downloader 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.offline.Downloader 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