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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations