Search in sources :

Example 6 with DummyMainThread

use of com.google.android.exoplayer2.testutil.DummyMainThread in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationSetShuffleOrder.

@Test
public void customCallbackBeforePreparationSetShuffleOrder() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> mediaSource.setShuffleOrder(new ShuffleOrder.UnshuffledShuffleOrder(/* length= */
    0), Util.createHandlerForCurrentLooper(), runnableInvoked::countDown));
    runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, MILLISECONDS);
    testThread.release();
    assertThat(runnableInvoked.getCount()).isEqualTo(0);
}
Also used : DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with DummyMainThread

use of com.google.android.exoplayer2.testutil.DummyMainThread in project ExoPlayer by google.

the class DownloadManagerTest method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    testThread = new DummyMainThread();
    setupDownloadManager(/* maxParallelDownloads= */
    100);
}
Also used : DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) Before(org.junit.Before)

Example 8 with DummyMainThread

use of com.google.android.exoplayer2.testutil.DummyMainThread in project ExoPlayer by google.

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(com.google.android.exoplayer2.scheduler.Scheduler) DownloadManager(com.google.android.exoplayer2.offline.DownloadManager) DownloadService(com.google.android.exoplayer2.offline.DownloadService) Notification(android.app.Notification) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) Download(com.google.android.exoplayer2.offline.Download) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DefaultDownloadIndex(com.google.android.exoplayer2.offline.DefaultDownloadIndex) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Nullable(androidx.annotation.Nullable) TestDownloadManagerListener(com.google.android.exoplayer2.robolectric.TestDownloadManagerListener) Before(org.junit.Before)

Example 9 with DummyMainThread

use of com.google.android.exoplayer2.testutil.DummyMainThread in project ExoPlayer by google.

the class MediaPeriodAsserts method prepareAndGetTrackGroups.

private static TrackGroupArray prepareAndGetTrackGroups(MediaPeriod mediaPeriod) {
    AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>();
    DummyMainThread testThread = new DummyMainThread();
    ConditionVariable preparedCondition = new ConditionVariable();
    testThread.runOnMainThread(() -> mediaPeriod.prepare(new Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            trackGroupArray.set(mediaPeriod.getTrackGroups());
            preparedCondition.open();
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
        // Ignore.
        }
    }, /* positionUs= */
    0));
    try {
        preparedCondition.block();
    } catch (InterruptedException e) {
    // Ignore.
    }
    testThread.release();
    return trackGroupArray.get();
}
Also used : ConditionVariable(com.google.android.exoplayer2.util.ConditionVariable) Callback(com.google.android.exoplayer2.source.MediaPeriod.Callback) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) AtomicReference(java.util.concurrent.atomic.AtomicReference) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod)

Example 10 with DummyMainThread

use of com.google.android.exoplayer2.testutil.DummyMainThread in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationAddMultiple.

@Test
public void customCallbackAfterPreparationAddMultiple() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        testRunner.prepareSource();
        final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { createFakeMediaSource(), createFakeMediaSource() }), Util.createHandlerForCurrentLooper(), timelineGrabber));
        Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
        assertThat(timeline.getWindowCount()).isEqualTo(2);
    } finally {
        testThread.release();
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) Test(org.junit.Test)

Aggregations

DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)20 Test (org.junit.Test)16 Timeline (com.google.android.exoplayer2.Timeline)8 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 Before (org.junit.Before)4 Context (android.content.Context)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 StreamKey (com.google.android.exoplayer2.offline.StreamKey)2 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)2 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)2 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)2 Notification (android.app.Notification)1 Handler (android.os.Handler)1 Nullable (androidx.annotation.Nullable)1 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)1 Download (com.google.android.exoplayer2.offline.Download)1 DownloadManager (com.google.android.exoplayer2.offline.DownloadManager)1 DownloadService (com.google.android.exoplayer2.offline.DownloadService)1