Search in sources :

Example 11 with DummyMainThread

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

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

Example 12 with DummyMainThread

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

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

Example 13 with DummyMainThread

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

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

Example 14 with DummyMainThread

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

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

Example 15 with DummyMainThread

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

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