Search in sources :

Example 1 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationRemove.

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

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationMove.

@Test
public void customCallbackAfterPreparationMove() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        testRunner.prepareSource();
        testThread.runOnMainThread(() -> mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { createFakeMediaSource(), createFakeMediaSource() })));
        testRunner.assertTimelineChangeBlocking();
        final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.moveMediaSource(/* currentIndex= */
        1, /* newIndex= */
        0, 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 3 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationSetShuffleOrder.

@Test
public void customCallbackAfterPreparationSetShuffleOrder() throws Exception {
    DummyMainThread testThread = new DummyMainThread();
    try {
        mediaSource.addMediaSources(Arrays.asList(createFakeMediaSource(), createFakeMediaSource(), createFakeMediaSource()));
        testRunner.prepareSource();
        TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
        testThread.runOnMainThread(() -> mediaSource.setShuffleOrder(new ShuffleOrder.UnshuffledShuffleOrder(/* length= */
        3), Util.createHandlerForCurrentLooper(), timelineGrabber));
        Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
        assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */
        true)).isEqualTo(0);
    } 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 4 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackBeforePreparationAddSingle.

@Test
public void customCallbackBeforePreparationAddSingle() throws Exception {
    CountDownLatch runnableInvoked = new CountDownLatch(1);
    DummyMainThread testThread = new DummyMainThread();
    testThread.runOnMainThread(() -> mediaSource.addMediaSource(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 5 with DummyMainThread

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

the class ConcatenatingMediaSourceTest method customCallbackAfterPreparationAddSingleWithIndex.

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

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