Search in sources :

Example 51 with Cache

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

Example 52 with Cache

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);
}
Also used : CacheDataSink(com.google.android.exoplayer2.upstream.cache.CacheDataSink) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource)

Example 53 with Cache

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);
    }
}
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

Test (org.junit.Test)25 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)19 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)18 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)16 StreamKey (com.google.android.exoplayer2.offline.StreamKey)9 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)9 DataSource (com.google.android.exoplayer2.upstream.DataSource)8 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)8 File (java.io.File)8 Uri (android.net.Uri)7 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)6 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)6 IOException (java.io.IOException)6 Before (org.junit.Before)6 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)5 Nullable (androidx.annotation.Nullable)3 Notification (android.app.Notification)2 NotificationManager (android.app.NotificationManager)2 Context (android.content.Context)2 SQLException (android.database.SQLException)2