Search in sources :

Example 1 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DummyMainThread(androidx.media3.test.utils.DummyMainThread) Test(org.junit.Test)

Example 2 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread in project media by androidx.

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 : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) DummyMainThread(androidx.media3.test.utils.DummyMainThread) Test(org.junit.Test)

Example 3 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread in project media by androidx.

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(androidx.media3.test.utils.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread in project media by androidx.

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(androidx.media3.test.utils.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with DummyMainThread

use of androidx.media3.test.utils.DummyMainThread in project media by androidx.

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(androidx.media3.test.utils.DummyMainThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

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