Search in sources :

Example 11 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationMove.

@Test
public void customCallbackBeforePreparationMove() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> {
        mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { createFakeMediaSource(), createFakeMediaSource() }));
        mediaSource.moveMediaSource(/* currentIndex= */
        1, /* newIndex= */
        0, Util.createHandlerForCurrentLooper(), runnableInvoked::countDown);
    });
    runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, MILLISECONDS);
    testThread.release();
    assertThat(runnableInvoked.getCount()).isEqualTo(0);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationAddMultipleWithIndex.

@Test
public void customCallbackAfterPreparationAddMultipleWithIndex() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        testRunner.prepareSource();
        final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.addMediaSources(/* index */
        0, 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)

Example 13 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationAddMultiple.

@Test
public void customCallbackBeforePreparationAddMultiple() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { createFakeMediaSource(), 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 14 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationAddMultipleWithIndex.

@Test
public void customCallbackBeforePreparationAddMultipleWithIndex() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> mediaSource.addMediaSources(/* index */
    0, Arrays.asList(new MediaSource[] { createFakeMediaSource(), 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 15 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method clear.

@Test
public void clear() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    final FakeMediaSource preparedChildSource = createFakeMediaSource();
    final FakeMediaSource unpreparedChildSource = new FakeMediaSource(/* timeline= */
    null);
    testThread.runOnMainThread(() -> {
        mediaSource.addMediaSource(preparedChildSource);
        mediaSource.addMediaSource(unpreparedChildSource);
    });
    testRunner.prepareSource();
    final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
    testThread.runOnMainThread(() -> mediaSource.clear(Util.createHandlerForCurrentLooper(), timelineGrabber));
    Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
    assertThat(timeline.isEmpty()).isTrue();
    preparedChildSource.assertReleased();
    unpreparedChildSource.assertReleased();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) 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