Search in sources :

Example 6 with Downloader

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);
}
Also used : CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) Downloader(com.google.android.exoplayer2.offline.Downloader) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 7 with Downloader

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);
    }
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Nullable(androidx.annotation.Nullable)

Example 8 with Downloader

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);
}
Also used : FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) Test(org.junit.Test)

Example 9 with Downloader

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);
    }
}
Also used : ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) OkHttpDataSource(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) OkHttpDataSource(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource)

Aggregations

CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)7 Test (org.junit.Test)6 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 Uri (android.net.Uri)3 MediaItem (com.google.android.exoplayer2.MediaItem)3 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)3 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 StreamKey (com.google.android.exoplayer2.offline.StreamKey)3 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)3 OkHttpDataSource (com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 IOException (java.io.IOException)2 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 AsyncTask (android.os.AsyncTask)1 Nullable (androidx.annotation.Nullable)1 NotificationCompat (androidx.core.app.NotificationCompat)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)1