Search in sources :

Example 1 with DownloaderFactory

use of androidx.media3.exoplayer.offline.DownloaderFactory in project media by androidx.

the class HlsDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_M3U8).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(HlsDownloader.class);
}
Also used : CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Downloader(androidx.media3.exoplayer.offline.Downloader) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 2 with DownloaderFactory

use of androidx.media3.exoplayer.offline.DownloaderFactory in project media by androidx.

the class SsDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() throws Exception {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_SS).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(SsDownloader.class);
}
Also used : CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) Downloader(androidx.media3.exoplayer.offline.Downloader) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 3 with DownloaderFactory

use of androidx.media3.exoplayer.offline.DownloaderFactory in project media by androidx.

the class DashDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_MPD).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(DashDownloader.class);
}
Also used : CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Downloader(androidx.media3.exoplayer.offline.Downloader) DownloaderFactory(androidx.media3.exoplayer.offline.DownloaderFactory) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 4 with DownloaderFactory

use of androidx.media3.exoplayer.offline.DownloaderFactory in project media by androidx.

the class DownloadManagerDashTest method createDownloadManager.

private void createDownloadManager() {
    runOnMainThread(() -> {
        Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
        DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
        Runnable::run);
        downloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
        downloadManager.setRequirements(new Requirements(0));
        downloadManagerListener = new TestDownloadManagerListener(downloadManager);
        downloadManager.resumeDownloads();
    });
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) TestRunnable(androidx.media3.test.utils.DummyMainThread.TestRunnable) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Factory(androidx.media3.datasource.DataSource.Factory) DownloadManager(androidx.media3.exoplayer.offline.DownloadManager) Requirements(androidx.media3.exoplayer.scheduler.Requirements) TestDownloadManagerListener(androidx.media3.test.utils.robolectric.TestDownloadManagerListener)

Example 5 with DownloaderFactory

use of androidx.media3.exoplayer.offline.DownloaderFactory in project media by androidx.

the class DownloadServiceDashTest method setUp.

@Before
public void setUp() throws IOException {
    testThread = new DummyMainThread();
    context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    Runnable pauseAction = () -> {
        if (pauseDownloadCondition != null) {
            try {
                pauseDownloadCondition.block();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    };
    fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().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);
    final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    testThread.runTestOnMainThread(() -> {
        DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
        DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
        Runnable::run);
        final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
        downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
        dashDownloadManager.resumeDownloads();
        dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {

            @Override
            protected DownloadManager getDownloadManager() {
                return dashDownloadManager;
            }

            @Override
            @Nullable
            protected Scheduler getScheduler() {
                return null;
            }

            @Override
            protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
                throw new UnsupportedOperationException();
            }
        };
        dashDownloadService.onCreate();
    });
}
Also used : Scheduler(androidx.media3.exoplayer.scheduler.Scheduler) DownloadManager(androidx.media3.exoplayer.offline.DownloadManager) DownloadService(androidx.media3.exoplayer.offline.DownloadService) Notification(android.app.Notification) SimpleCache(androidx.media3.datasource.cache.SimpleCache) FakeDataSource(androidx.media3.test.utils.FakeDataSource) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) DefaultDownloaderFactory(androidx.media3.exoplayer.offline.DefaultDownloaderFactory) Download(androidx.media3.exoplayer.offline.Download) NoOpCacheEvictor(androidx.media3.datasource.cache.NoOpCacheEvictor) FakeDataSet(androidx.media3.test.utils.FakeDataSet) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) FakeDataSource(androidx.media3.test.utils.FakeDataSource) DataSource(androidx.media3.datasource.DataSource) DefaultDownloadIndex(androidx.media3.exoplayer.offline.DefaultDownloadIndex) DummyMainThread(androidx.media3.test.utils.DummyMainThread) StreamKey(androidx.media3.common.StreamKey) Nullable(androidx.annotation.Nullable) TestDownloadManagerListener(androidx.media3.test.utils.robolectric.TestDownloadManagerListener) Before(org.junit.Before)

Aggregations

CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)5 DefaultDownloaderFactory (androidx.media3.exoplayer.offline.DefaultDownloaderFactory)5 StreamKey (androidx.media3.common.StreamKey)4 Downloader (androidx.media3.exoplayer.offline.Downloader)3 DownloaderFactory (androidx.media3.exoplayer.offline.DownloaderFactory)3 Test (org.junit.Test)3 DownloadManager (androidx.media3.exoplayer.offline.DownloadManager)2 FakeDataSource (androidx.media3.test.utils.FakeDataSource)2 TestDownloadManagerListener (androidx.media3.test.utils.robolectric.TestDownloadManagerListener)2 Notification (android.app.Notification)1 Nullable (androidx.annotation.Nullable)1 DataSource (androidx.media3.datasource.DataSource)1 Factory (androidx.media3.datasource.DataSource.Factory)1 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)1 SimpleCache (androidx.media3.datasource.cache.SimpleCache)1 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)1 Download (androidx.media3.exoplayer.offline.Download)1 DownloadService (androidx.media3.exoplayer.offline.DownloadService)1 Requirements (androidx.media3.exoplayer.scheduler.Requirements)1 Scheduler (androidx.media3.exoplayer.scheduler.Scheduler)1