Search in sources :

Example 16 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationAddSingleWithIndex.

@Test
public void customCallbackBeforePreparationAddSingleWithIndex() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> mediaSource.addMediaSource(/* index */
    0, createFakeMediaSource(), 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 17 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationRemove.

@Test
public void customCallbackBeforePreparationRemove() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> {
        mediaSource.addMediaSource(createFakeMediaSource());
        mediaSource.removeMediaSource(/* index */
        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 18 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationAddSingle.

@Test
public void customCallbackAfterPreparationAddSingle() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        testRunner.prepareSource();
        final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.addMediaSource(createFakeMediaSource(), Util.createHandlerForCurrentLooper(), timelineGrabber));
        Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
        assertThat(timeline.getWindowCount()).isEqualTo(1);
    } 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)

Example 19 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackIsCalledAfterRelease.

@Test
public void customCallbackIsCalledAfterRelease() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    CountDownLatch callbackCalledCondition = new CountDownLatch(1);
    try {
        testThread.runOnMainThread(() -> {
            MediaSourceCaller caller = mock(MediaSourceCaller.class);
            mediaSource.addMediaSources(Arrays.asList(createMediaSources(2)));
            mediaSource.prepareSource(caller, /* mediaTransferListener= */
            null, PlayerId.UNSET);
            mediaSource.moveMediaSource(/* currentIndex= */
            0, /* newIndex= */
            1, Util.createHandlerForCurrentLooper(), callbackCalledCondition::countDown);
            mediaSource.releaseSource(caller);
        });
        assertThat(callbackCalledCondition.await(MediaSourceTestRunner.TIMEOUT_MS, MILLISECONDS)).isTrue();
    } finally {
        testThread.release();
    }
}
Also used : MediaSourceCaller(com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 20 with DummyMainThread

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

the class StreamVolumeManagerTest method setUp.

@Before
public void setUp() {
    Context context = ApplicationProvider.getApplicationContext();
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    testListener = new TestListener();
    testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> streamVolumeManager = new StreamVolumeManager(context, new Handler(Looper.myLooper()), testListener));
}
Also used : Context(android.content.Context) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) Handler(android.os.Handler) Before(org.junit.Before)

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