Search in sources :

Example 1 with SimpleCache

use of androidx.media3.datasource.cache.SimpleCache in project media by androidx.

the class DemoUtil method getDownloadCache.

private static synchronized Cache getDownloadCache(Context context) {
    if (downloadCache == null) {
        File downloadContentDirectory = new File(getDownloadDirectory(context), DOWNLOAD_CONTENT_DIRECTORY);
        downloadCache = new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor(), getDatabaseProvider(context));
    }
    return downloadCache;
}
Also used : SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) File(java.io.File)

Example 2 with SimpleCache

use of androidx.media3.datasource.cache.SimpleCache in project media by androidx.

the class DashDownloaderTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    progressListener = new ProgressListener();
}
Also used : SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) Before(org.junit.Before)

Example 3 with SimpleCache

use of androidx.media3.datasource.cache.SimpleCache in project media by androidx.

the class DashDownloadTest method setUp.

@Before
public void setUp() throws Exception {
    testRunner = new DashTestRunner(TAG, testRule.getActivity()).setManifestUrl(DashTestData.H264_MANIFEST).setFullPlaybackNoSeeking(true).setCanIncludeAdditionalVideoFormats(false).setAudioVideoFormats(DashTestData.AAC_AUDIO_REPRESENTATION_ID, DashTestData.H264_CDD_FIXED);
    tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), new StandaloneDatabaseProvider(testRule.getActivity()));
    httpDataSourceFactory = new DefaultHttpDataSource.Factory();
    offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
}
Also used : SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) StandaloneDatabaseProvider(androidx.media3.database.StandaloneDatabaseProvider) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) Before(org.junit.Before)

Example 4 with SimpleCache

use of androidx.media3.datasource.cache.SimpleCache in project media by androidx.

the class CacheDataSourceTest method setUp.

@Before
public void setUp() throws Exception {
    testDataUri = Uri.parse("https://www.test.com/data");
    httpRequestHeaders = new HashMap<>();
    httpRequestHeaders.put("Test-key", "Test-val");
    unboundedDataSpec = buildDataSpec(/* unbounded= */
    true, /* key= */
    null);
    boundedDataSpec = buildDataSpec(/* unbounded= */
    false, /* key= */
    null);
    unboundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    true, DATASPEC_KEY);
    boundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    false, DATASPEC_KEY);
    defaultCacheKey = CacheKeyFactory.DEFAULT.buildCacheKey(unboundedDataSpec);
    customCacheKey = "customKey." + defaultCacheKey;
    cacheKeyFactory = dataSpec -> customCacheKey;
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    upstreamDataSource = new FakeDataSource();
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) Before(org.junit.Before)

Example 5 with SimpleCache

use of androidx.media3.datasource.cache.SimpleCache in project media by androidx.

the class CacheDataSourceTest2 method buildCacheDataSource.

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(), TestUtil.getInMemoryDatabaseProvider());
    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, // eventListener
    null);
}
Also used : DataSink(androidx.media3.datasource.DataSink) AesCipherDataSink(androidx.media3.datasource.AesCipherDataSink) FileDataSource(androidx.media3.datasource.FileDataSource) DataSource(androidx.media3.datasource.DataSource) FakeDataSource(androidx.media3.test.utils.FakeDataSource) AesCipherDataSource(androidx.media3.datasource.AesCipherDataSource) AesCipherDataSink(androidx.media3.datasource.AesCipherDataSink) FileDataSource(androidx.media3.datasource.FileDataSource) AesCipherDataSource(androidx.media3.datasource.AesCipherDataSource) File(java.io.File)

Aggregations

NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)7 SimpleCache (androidx.media3.datasource.cache.SimpleCache)7 Before (org.junit.Before)7 FakeDataSource (androidx.media3.test.utils.FakeDataSource)4 File (java.io.File)4 FakeDataSet (androidx.media3.test.utils.FakeDataSet)3 StreamKey (androidx.media3.common.StreamKey)2 DataSource (androidx.media3.datasource.DataSource)2 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)2 DummyMainThread (androidx.media3.test.utils.DummyMainThread)2 Notification (android.app.Notification)1 Context (android.content.Context)1 Nullable (androidx.annotation.Nullable)1 DatabaseProvider (androidx.media3.database.DatabaseProvider)1 StandaloneDatabaseProvider (androidx.media3.database.StandaloneDatabaseProvider)1 AesCipherDataSink (androidx.media3.datasource.AesCipherDataSink)1 AesCipherDataSource (androidx.media3.datasource.AesCipherDataSource)1 DataSink (androidx.media3.datasource.DataSink)1 DefaultHttpDataSource (androidx.media3.datasource.DefaultHttpDataSource)1 FileDataSource (androidx.media3.datasource.FileDataSource)1