Search in sources :

Example 36 with MediaItem

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

the class ExoPlayerTest method mediaItemOfSources_correctInTimelineWindows.

@Test
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
    TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake1"));
    FakeMediaSource fakeMediaSource1 = new FakeMediaSource(new FakeTimeline(window1));
    TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake2"));
    FakeMediaSource fakeMediaSource2 = new FakeMediaSource(new FakeTimeline(window2));
    TimelineWindowDefinition window3 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    3, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake3"));
    FakeMediaSource fakeMediaSource3 = new FakeMediaSource(new FakeTimeline(window3));
    final Player[] playerHolder = { null };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            playerHolder[0] = player;
        }
    }).waitForPlaybackState(Player.STATE_READY).seek(/* positionMs= */
    0).play().build();
    List<MediaItem> currentMediaItems = new ArrayList<>();
    List<MediaItem> mediaItemsInTimeline = new ArrayList<>();
    Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onTimelineChanged(Timeline timeline, int reason) {
            if (reason != Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
                return;
            }
            Window window = new Window();
            for (int i = 0; i < timeline.getWindowCount(); i++) {
                mediaItemsInTimeline.add(timeline.getWindow(i, window).mediaItem);
            }
        }

        @Override
        public void onPositionDiscontinuity(int reason) {
            if (reason == Player.DISCONTINUITY_REASON_SEEK || reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
                currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
            }
        }
    };
    new ExoPlayerTestRunner.Builder(context).setPlayerListener(playerListener).setActionSchedule(actionSchedule).setMediaSources(fakeMediaSource1, fakeMediaSource2, fakeMediaSource3).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(currentMediaItems.get(0).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake1");
    assertThat(currentMediaItems.get(1).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake2");
    assertThat(currentMediaItems.get(2).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake3");
    assertThat(mediaItemsInTimeline).containsExactlyElementsIn(currentMediaItems);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 37 with MediaItem

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

the class SinglePeriodTimelineTest method getWindow_setsMediaItemAndTag.

// Tests backward compatibility.
@SuppressWarnings("deprecation")
@Test
public void getWindow_setsMediaItemAndTag() {
    MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(new Object()).build();
    SinglePeriodTimeline timeline = new SinglePeriodTimeline(/* durationUs= */
    C.TIME_UNSET, /* isSeekable= */
    false, /* isDynamic= */
    false, /* isLive= */
    false, /* manifest= */
    null, mediaItem);
    Window window = timeline.getWindow(/* windowIndex= */
    0, this.window);
    assertThat(window.mediaItem).isEqualTo(mediaItem);
    assertThat(window.tag).isEqualTo(mediaItem.localConfiguration.tag);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 38 with MediaItem

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

the class SilenceMediaSourceTest method newInstance_setsMediaItem.

@Test
public void newInstance_setsMediaItem() {
    SilenceMediaSource mediaSource = new SilenceMediaSource(1_000_000);
    MediaItem mediaItem = mediaSource.getMediaItem();
    assertThat(mediaItem).isNotNull();
    assertThat(mediaItem.mediaId).isEqualTo(SilenceMediaSource.MEDIA_ID);
    assertThat(mediaSource.getMediaItem().localConfiguration.uri).isEqualTo(Uri.EMPTY);
    assertThat(mediaItem.localConfiguration.mimeType).isEqualTo(MimeTypes.AUDIO_RAW);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 39 with MediaItem

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

the class DefaultDrmSessionManagerProviderTest method create_reusesCachedInstanceWherePossible.

@Test
public void create_reusesCachedInstanceWherePossible() {
    MediaItem mediaItem1 = new MediaItem.Builder().setUri("https://example.test/content-1").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
    // Same DRM info as item1, but different URL to check it doesn't prevent re-using a manager.
    MediaItem mediaItem2 = new MediaItem.Builder().setUri("https://example.test/content-2").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
    // Different DRM info to 1 and 2, needs a different manager instance.
    MediaItem mediaItem3 = new MediaItem.Builder().setUri("https://example.test/content-3").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).setLicenseUri("https://example.test/license").build()).build();
    DefaultDrmSessionManagerProvider provider = new DefaultDrmSessionManagerProvider();
    DrmSessionManager drmSessionManager1 = provider.get(mediaItem1);
    DrmSessionManager drmSessionManager2 = provider.get(mediaItem2);
    DrmSessionManager drmSessionManager3 = provider.get(mediaItem3);
    // Get a manager for the first item again - expect it to be a different instance to last time
    // since we only cache one.
    DrmSessionManager drmSessionManager4 = provider.get(mediaItem1);
    assertThat(drmSessionManager1).isSameInstanceAs(drmSessionManager2);
    assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager3);
    assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager4);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManagerProvider(com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider) Test(org.junit.Test)

Example 40 with MediaItem

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

the class DefaultDrmSessionManagerProviderTest method create_createsManager.

@Test
public void create_createsManager() {
    MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).setLicenseUri(Uri.EMPTY).build()).build();
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManagerProvider().get(mediaItem);
    assertThat(drmSessionManager).isNotEqualTo(DrmSessionManager.DRM_UNSUPPORTED);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManagerProvider(com.google.android.exoplayer2.drm.DefaultDrmSessionManagerProvider) 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