Search in sources :

Example 1 with DefaultMediaSourceFactory

use of androidx.media3.exoplayer.source.DefaultMediaSourceFactory in project media by androidx.

the class PlayerActivity method createMediaSourceFactory.

private MediaSource.Factory createMediaSourceFactory() {
    ImaServerSideAdInsertionMediaSource.AdsLoader.Builder serverSideAdLoaderBuilder = new ImaServerSideAdInsertionMediaSource.AdsLoader.Builder(/* context= */
    this, playerView);
    if (serverSideAdsLoaderState != null) {
        serverSideAdLoaderBuilder.setAdsLoaderState(serverSideAdsLoaderState);
    }
    serverSideAdsLoader = serverSideAdLoaderBuilder.build();
    ImaServerSideAdInsertionMediaSource.Factory imaServerSideAdInsertionMediaSourceFactory = new ImaServerSideAdInsertionMediaSource.Factory(serverSideAdsLoader, new DefaultMediaSourceFactory(dataSourceFactory));
    return new DefaultMediaSourceFactory(dataSourceFactory).setAdsLoaderProvider(this::getClientSideAdsLoader).setAdViewProvider(playerView).setServerSideAdInsertionMediaSourceFactory(imaServerSideAdInsertionMediaSourceFactory);
}
Also used : DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) ImaServerSideAdInsertionMediaSource(androidx.media3.exoplayer.ima.ImaServerSideAdInsertionMediaSource) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) AdsLoader(androidx.media3.exoplayer.source.ads.AdsLoader) ImaAdsLoader(androidx.media3.exoplayer.ima.ImaAdsLoader)

Example 2 with DefaultMediaSourceFactory

use of androidx.media3.exoplayer.source.DefaultMediaSourceFactory in project media by androidx.

the class DefaultMediaSourceFactoryTest method createMediaSource_withMimeType_dashSource.

@Test
public void createMediaSource_withMimeType_dashSource() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setMimeType(MimeTypes.APPLICATION_MPD).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(DashMediaSource.class);
}
Also used : MediaSource(androidx.media3.exoplayer.source.MediaSource) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 3 with DefaultMediaSourceFactory

use of androidx.media3.exoplayer.source.DefaultMediaSourceFactory in project media by androidx.

the class DefaultMediaSourceFactoryTest method createMediaSource_withTag_tagInSource.

@Test
public void createMediaSource_withTag_tagInSource() {
    Object tag = new Object();
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setMimeType(MimeTypes.APPLICATION_MPD).setTag(tag).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource.getMediaItem().localConfiguration.tag).isEqualTo(tag);
}
Also used : MediaSource(androidx.media3.exoplayer.source.MediaSource) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 4 with DefaultMediaSourceFactory

use of androidx.media3.exoplayer.source.DefaultMediaSourceFactory in project media by androidx.

the class DefaultMediaSourceFactoryTest method createMediaSource_withPath_hlsSource.

@Test
public void createMediaSource_withPath_hlsSource() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA + "/file.m3u8").build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(HlsMediaSource.class);
}
Also used : MediaSource(androidx.media3.exoplayer.source.MediaSource) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 5 with DefaultMediaSourceFactory

use of androidx.media3.exoplayer.source.DefaultMediaSourceFactory in project media by androidx.

the class ImaAdsLoaderTest method resumePlaybackBeforeMidroll_withoutPlayAdBeforeStartPosition_skipsPreroll.

@Test
public void resumePlaybackBeforeMidroll_withoutPlayAdBeforeStartPosition_skipsPreroll() {
    imaAdsLoader = new ImaAdsLoader.Builder(getApplicationContext()).setPlayAdBeforeStartPosition(false).setImaFactory(mockImaFactory).setImaSdkSettings(mockImaSdkSettings).build();
    imaAdsLoader.setPlayer(fakePlayer);
    adsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, TEST_ADS_ID, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
    long midrollWindowTimeUs = 2 * C.MICROS_PER_SECOND;
    long midrollPeriodTimeUs = midrollWindowTimeUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    ImmutableList<Float> cuePoints = ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND);
    when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
    fakePlayer.setPlayingContentPosition(/* periodIndex= */
    0, Util.usToMs(midrollWindowTimeUs) - 1_000);
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    ArgumentCaptor<Double> playAdsAfterTimeCaptor = ArgumentCaptor.forClass(Double.class);
    verify(mockAdsRenderingSettings).setPlayAdsAfterTime(playAdsAfterTimeCaptor.capture());
    double expectedPlayAdsAfterTimeUs = midrollPeriodTimeUs / 2d;
    assertThat(playAdsAfterTimeCaptor.getValue()).isWithin(0.1d).of(expectedPlayAdsAfterTimeUs / C.MICROS_PER_SECOND);
    assertThat(getAdPlaybackState(/* periodIndex= */
    0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withSkippedAdGroup(/* adGroupIndex= */
    0).withContentDurationUs(CONTENT_PERIOD_DURATION_US));
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) AdPlaybackState(androidx.media3.common.AdPlaybackState) AdsMediaSource(androidx.media3.exoplayer.source.ads.AdsMediaSource) ArgumentMatchers.anyDouble(org.mockito.ArgumentMatchers.anyDouble) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 DefaultMediaSourceFactory (androidx.media3.exoplayer.source.DefaultMediaSourceFactory)35 MediaItem (androidx.media3.common.MediaItem)33 AdsMediaSource (androidx.media3.exoplayer.source.ads.AdsMediaSource)27 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)16 Context (android.content.Context)15 MediaSource (androidx.media3.exoplayer.source.MediaSource)15 AdPlaybackState (androidx.media3.common.AdPlaybackState)11 SurfaceTexture (android.graphics.SurfaceTexture)5 Surface (android.view.Surface)5 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)5 CapturingRenderersFactory (androidx.media3.test.utils.CapturingRenderersFactory)5 FakeClock (androidx.media3.test.utils.FakeClock)5 PlaybackOutput (androidx.media3.test.utils.robolectric.PlaybackOutput)5 ApplicationProvider (androidx.test.core.app.ApplicationProvider)5 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 RunWith (org.junit.runner.RunWith)5 Pair (android.util.Pair)4 Player (androidx.media3.common.Player)4