Search in sources :

Example 21 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread 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)

Aggregations

DummyMainThread (androidx.media3.test.utils.DummyMainThread)20 Test (org.junit.Test)16 Timeline (androidx.media3.common.Timeline)8 FakeTimeline (androidx.media3.test.utils.FakeTimeline)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 Before (org.junit.Before)4 Context (android.content.Context)2 StreamKey (androidx.media3.common.StreamKey)2 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)2 SimpleCache (androidx.media3.datasource.cache.SimpleCache)2 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)2 FakeDataSet (androidx.media3.test.utils.FakeDataSet)2 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)2 Notification (android.app.Notification)1 Handler (android.os.Handler)1 Nullable (androidx.annotation.Nullable)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 ConditionVariable (androidx.media3.common.util.ConditionVariable)1 DataSource (androidx.media3.datasource.DataSource)1 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)1