Search in sources :

Example 16 with DummyMainThread

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

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

Example 17 with DummyMainThread

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

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

Example 18 with DummyMainThread

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

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

Example 19 with DummyMainThread

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

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

Example 20 with DummyMainThread

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

the class DownloadManagerDashTest method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    testThread = new DummyMainThread();
    Context context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    File cacheFolder = new File(tempFolder, "cache");
    cacheFolder.mkdir();
    cache = new SimpleCache(cacheFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    MockitoAnnotations.initMocks(this);
    fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
    createDownloadManager();
}
Also used : Context(android.content.Context) DefaultDownloadIndex(androidx.media3.exoplayer.offline.DefaultDownloadIndex) SimpleCache(androidx.media3.datasource.cache.SimpleCache) DummyMainThread(androidx.media3.test.utils.DummyMainThread) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) FakeDataSet(androidx.media3.test.utils.FakeDataSet) File(java.io.File) StreamKey(androidx.media3.common.StreamKey) Before(org.junit.Before)

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