Search in sources :

Example 46 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_withAdsConfigurationProvidersNull_playsWithoutAdNoException.

@Test
public void createMediaSource_withAdsConfigurationProvidersNull_playsWithoutAdNoException() {
    Context applicationContext = ApplicationProvider.getApplicationContext();
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setAdsConfiguration(new MediaItem.AdsConfiguration.Builder(Uri.parse(URI_MEDIA)).build()).build();
    MediaSource mediaSource = new DefaultMediaSourceFactory(applicationContext).createMediaSource(mediaItem);
    assertThat(mediaSource).isNotInstanceOf(AdsMediaSource.class);
}
Also used : Context(android.content.Context) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 47 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_withMediaItemLiveProperties_overridesFactoryLiveProperties.

@Test
public void createMediaSource_withMediaItemLiveProperties_overridesFactoryLiveProperties() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext()).setLiveTargetOffsetMs(20).setLiveMinOffsetMs(2222).setLiveMinOffsetMs(4444).setLiveMinSpeed(.1f).setLiveMaxSpeed(2.0f);
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA + "/file.mp4").setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(10).setMinOffsetMs(1111).setMinOffsetMs(3333).setMinPlaybackSpeed(20.0f).setMaxPlaybackSpeed(20.0f).build()).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    MediaItem mediaItemFromSource = mediaSource.getMediaItem();
    assertThat(mediaItemFromSource).isEqualTo(mediaItem);
}
Also used : Context(android.content.Context) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 48 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_withAdsConfiguration_callsAdsLoader.

@Test
public void createMediaSource_withAdsConfiguration_callsAdsLoader() {
    Uri adTagUri = Uri.parse(URI_MEDIA);
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setAdsConfiguration(new MediaItem.AdsConfiguration.Builder(adTagUri).build()).build();
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext()).setAdsLoaderProvider(ignoredAdsConfiguration -> mock(AdsLoader.class)).setAdViewProvider(mock(AdViewProvider.class));
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(AdsMediaSource.class);
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) MediaItem(com.google.android.exoplayer2.MediaItem) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AdsLoader(com.google.android.exoplayer2.source.ads.AdsLoader) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AdViewProvider(com.google.android.exoplayer2.ui.AdViewProvider) ApplicationProvider(androidx.test.core.app.ApplicationProvider) List(java.util.List) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) Mockito.mock(org.mockito.Mockito.mock) C(com.google.android.exoplayer2.C) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) AdViewProvider(com.google.android.exoplayer2.ui.AdViewProvider) Uri(android.net.Uri) Test(org.junit.Test)

Example 49 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_defaultToEnd_isNotClippingMediaSource.

@Test
public void createMediaSource_defaultToEnd_isNotClippingMediaSource() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setClippingConfiguration(new MediaItem.ClippingConfiguration.Builder().setEndPositionMs(C.TIME_END_OF_SOURCE).build()).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(ProgressiveMediaSource.class);
}
Also used : AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 50 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class HlsMediaSourceTest method loadLivePlaylist_noTargetLiveOffsetDefined_fallbackToThreeTargetDuration.

@Test
public void loadLivePlaylist_noTargetLiveOffsetDefined_fallbackToThreeTargetDuration() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a duration of 16 seconds but not hold back or part hold back.
    String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:CAN-SKIP-UNTIL=24";
    // The playlist finishes 1 second before the current time, therefore there's a live edge
    // offset of 1 second.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
    HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
    MediaItem mediaItem = MediaItem.fromUri(playlistUri);
    HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
    Timeline timeline = prepareAndWaitForTimeline(mediaSource);
    Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
    // The target live offset is picked from target duration (3 * 4 = 12 seconds) and then expressed
    // in relation to the live edge (12 + 1 seconds).
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(13000);
    assertThat(window.liveConfiguration.minPlaybackSpeed).isEqualTo(1f);
    assertThat(window.liveConfiguration.maxPlaybackSpeed).isEqualTo(1f);
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)160 Test (org.junit.Test)151 MediaSource (com.google.android.exoplayer2.source.MediaSource)31 ArrayList (java.util.ArrayList)29 Timeline (com.google.android.exoplayer2.Timeline)25 InOrder (org.mockito.InOrder)20 Nullable (androidx.annotation.Nullable)19 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)19 Player (com.google.android.exoplayer2.Player)17 Uri (android.net.Uri)15 Listener (com.google.android.exoplayer2.Player.Listener)15 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)15 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)15 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)12