Search in sources :

Example 6 with SimpleCache

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

the class ProgressiveDownloaderTest method createDownloadCache.

@Before
public void createDownloadCache() throws Exception {
    testDir = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ProgressiveDownloaderTest");
    assertThat(testDir.delete()).isTrue();
    assertThat(testDir.mkdirs()).isTrue();
    DatabaseProvider databaseProvider = TestUtil.getInMemoryDatabaseProvider();
    downloadCache = new SimpleCache(testDir, new NoOpCacheEvictor(), databaseProvider);
}
Also used : DatabaseProvider(androidx.media3.database.DatabaseProvider) SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) Before(org.junit.Before)

Example 7 with SimpleCache

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

the class CacheDataSourceContractTest method createDataSource.

@Override
protected DataSource createDataSource() throws IOException {
    File tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    SimpleCache cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    upstreamDataSource = new FakeDataSource(fakeDataSet);
    return new CacheDataSource(cache, upstreamDataSource);
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) File(java.io.File)

Example 8 with SimpleCache

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

the class DownloadManagerDashTest method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    testThread = new DummyMainThread();
    Context context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    File cacheFolder = new File(tempFolder, "cache");
    cacheFolder.mkdir();
    cache = new SimpleCache(cacheFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    MockitoAnnotations.initMocks(this);
    fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
    createDownloadManager();
}
Also used : Context(android.content.Context) DefaultDownloadIndex(androidx.media3.exoplayer.offline.DefaultDownloadIndex) SimpleCache(androidx.media3.datasource.cache.SimpleCache) DummyMainThread(androidx.media3.test.utils.DummyMainThread) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) FakeDataSet(androidx.media3.test.utils.FakeDataSet) File(java.io.File) StreamKey(androidx.media3.common.StreamKey) Before(org.junit.Before)

Example 9 with SimpleCache

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

the class DownloadServiceDashTest method setUp.

@Before
public void setUp() throws IOException {
    testThread = new DummyMainThread();
    context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    Runnable pauseAction = () -> {
        if (pauseDownloadCondition != null) {
            try {
                pauseDownloadCondition.block();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    };
    fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    testThread.runTestOnMainThread(() -> {
        DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
        DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
        Runnable::run);
        final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
        downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
        dashDownloadManager.resumeDownloads();
        dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {

            @Override
            protected DownloadManager getDownloadManager() {
                return dashDownloadManager;
            }

            @Override
            @Nullable
            protected Scheduler getScheduler() {
                return null;
            }

            @Override
            protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
                throw new UnsupportedOperationException();
            }
        };
        dashDownloadService.onCreate();
    });
}
Also used : Scheduler(androidx.media3.exoplayer.scheduler.Scheduler) DownloadManager(androidx.media3.exoplayer.offline.DownloadManager) DownloadService(androidx.media3.exoplayer.offline.DownloadService) Notification(android.app.Notification) SimpleCache(androidx.media3.datasource.cache.SimpleCache) FakeDataSource(androidx.media3.test.utils.FakeDataSource) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Download(androidx.media3.exoplayer.offline.Download) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) FakeDataSet(androidx.media3.test.utils.FakeDataSet) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) FakeDataSource(androidx.media3.test.utils.FakeDataSource) DataSource(androidx.media3.datasource.DataSource) DefaultDownloadIndex(androidx.media3.exoplayer.offline.DefaultDownloadIndex) DummyMainThread(androidx.media3.test.utils.DummyMainThread) StreamKey(androidx.media3.common.StreamKey) Nullable(androidx.annotation.Nullable) TestDownloadManagerListener(androidx.media3.test.utils.robolectric.TestDownloadManagerListener) Before(org.junit.Before)

Example 10 with SimpleCache

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

the class HlsDownloaderTest method setUp.

@Before
public void setUp() throws Exception {
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    progressListener = new ProgressListener();
    fakeDataSet = new FakeDataSet().setData(MULTIVARIANT_PLAYLIST_URI, MULTIVARIANT_PLAYLIST_DATA).setData(MEDIA_PLAYLIST_1_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence0.ts", 10).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence1.ts", 11).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence2.ts", 12).setData(MEDIA_PLAYLIST_2_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence0.ts", 13).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence1.ts", 14).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence2.ts", 15);
}
Also used : SimpleCache(androidx.media3.datasource.cache.SimpleCache) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) FakeDataSet(androidx.media3.test.utils.FakeDataSet) Before(org.junit.Before)

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