use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_noHoldBackInPlaylistAndPlaybackSpeedInMediaItem_usesMediaItemConfiguration.
@Test
public void loadLivePlaylist_noHoldBackInPlaylistAndPlaybackSpeedInMediaItem_usesMediaItemConfiguration() throws TimeoutException, ParserException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
// The playlist has no hold back defined.
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";
// The playlist finishes 1 second before the current time. This should not affect the target
// live offset set in the media item.
SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:05.0+00:00"));
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(1000).setMinPlaybackSpeed(0.94f).setMaxPlaybackSpeed(1.02f).build()).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(window.liveConfiguration).isEqualTo(mediaItem.liveConfiguration);
assertThat(window.defaultPositionUs).isEqualTo(0);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_targetLiveOffsetLargerThanLiveWindow_targetLiveOffsetIsWithinLiveWindow.
@Test
public void loadLivePlaylist_targetLiveOffsetLargerThanLiveWindow_targetLiveOffsetIsWithinLiveWindow() throws TimeoutException, ParserException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
// The playlist has a duration of 8 seconds and a hold back of 12 seconds.
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" + "#EXT-X-SERVER-CONTROL:CAN-SKIP-UNTIL=24";
// The playlist finishes 1 second before the live edge, therefore the live window duration is
// 9 seconds (8 + 1).
SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:09.0+00:00"));
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(20_000).build()).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(mediaItem.liveConfiguration.targetOffsetMs).isGreaterThan(Util.usToMs(window.durationUs));
assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(9000);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_withoutProgramDateTime_targetLiveOffsetFromPlaylistNotAdjustedToLiveEdge.
@Test
public void loadLivePlaylist_withoutProgramDateTime_targetLiveOffsetFromPlaylistNotAdjustedToLiveEdge() throws TimeoutException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
// The playlist has a duration of 16 seconds and a hold back of 12 seconds.
String playlist = "#EXTM3U\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:HOLD-BACK=12";
// The playlist finishes 8 seconds before the current time.
SystemClock.setCurrentTimeMillis(20000);
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
// The target live offset is not adjusted to the live edge because the list does not have
// program date time.
assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(12000);
assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class HlsMediaSourceTest method loadOnDemandPlaylist_withNonPreciseStartTime_setsDefaultPosition.
@Test
public void loadOnDemandPlaylist_withNonPreciseStartTime_setsDefaultPosition() throws TimeoutException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
String playlist = "#EXTM3U\n" + "#EXT-X-PLAYLIST-TYPE:VOD\n" + "#EXT-X-TARGETDURATION:10\n" + "#EXT-X-VERSION:4\n" + "#EXT-X-START:TIME-OFFSET=15.000" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:10.0,\n" + "fileSequence1.ts\n" + "#EXTINF:10.0,\n" + "fileSequence2.ts\n" + "#EXT-X-ENDLIST";
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
// The target live offset is not adjusted to the live edge because the list does not have
// program date time.
assertThat(window.liveConfiguration).isNull();
assertThat(window.defaultPositionUs).isEqualTo(10000000);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class HlsMediaSourceTest method loadOnDemandPlaylist_withStartTimeBeforeTheBeginning_setsDefaultPositionToTheBeginning.
@Test
public void loadOnDemandPlaylist_withStartTimeBeforeTheBeginning_setsDefaultPositionToTheBeginning() throws TimeoutException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
String playlist = "#EXTM3U\n" + "#EXT-X-PLAYLIST-TYPE:VOD\n" + "#EXT-X-TARGETDURATION:10\n" + "#EXT-X-VERSION:4\n" + "#EXT-X-START:TIME-OFFSET=-35.000" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:10.0,\n" + "fileSequence1.ts\n" + "#EXTINF:10.0,\n" + "fileSequence2.ts\n" + "#EXT-X-ENDLIST";
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(window.liveConfiguration).isNull();
assertThat(window.defaultPositionUs).isEqualTo(0);
}
Aggregations