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