use of com.google.android.exoplayer2.upstream.DataSource.Factory 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.upstream.DataSource.Factory 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);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class HlsMediaSourceTest method refreshPlaylist_targetLiveOffsetRemainsInWindow.
@Test
public void refreshPlaylist_targetLiveOffsetRemainsInWindow() throws TimeoutException, IOException {
String playlistUri1 = "fake://foo.bar/media0/playlist1.m3u8";
// The playlist has a duration of 16 seconds and a hold back of 12 seconds.
String playlist1 = "#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 second playlist defines a different hold back.
String playlistUri2 = "fake://foo.bar/media0/playlist2.m3u8";
String playlist2 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence4.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence5.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence6.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence7.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:14";
// The third playlist has a duration of 8 seconds.
String playlistUri3 = "fake://foo.bar/media0/playlist3.m3u8";
String playlist3 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence8.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence9.ts\n" + "#EXTINF:4.00000,\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:12";
// The third playlist has a duration of 16 seconds but the target live offset should remain at
// 8 seconds.
String playlistUri4 = "fake://foo.bar/media0/playlist4.m3u8";
String playlist4 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence10.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence11.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence12.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence13.ts\n" + "#EXTINF:4.00000,\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:12";
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri1, playlist1);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri1).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
HlsMediaPlaylist secondPlaylist = parseHlsMediaPlaylist(playlistUri2, playlist2);
HlsMediaPlaylist thirdPlaylist = parseHlsMediaPlaylist(playlistUri3, playlist3);
HlsMediaPlaylist fourthPlaylist = parseHlsMediaPlaylist(playlistUri4, playlist4);
List<Timeline> timelines = new ArrayList<>();
MediaSource.MediaSourceCaller mediaSourceCaller = (source, timeline) -> timelines.add(timeline);
mediaSource.prepareSource(mediaSourceCaller, /* mediaTransferListener= */
null, PlayerId.UNSET);
runMainLooperUntil(() -> timelines.size() == 1);
mediaSource.onPrimaryPlaylistRefreshed(secondPlaylist);
runMainLooperUntil(() -> timelines.size() == 2);
mediaSource.onPrimaryPlaylistRefreshed(thirdPlaylist);
runMainLooperUntil(() -> timelines.size() == 3);
mediaSource.onPrimaryPlaylistRefreshed(fourthPlaylist);
runMainLooperUntil(() -> timelines.size() == 4);
Timeline.Window window = new Timeline.Window();
assertThat(timelines.get(0).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(12000);
assertThat(timelines.get(1).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(12000);
assertThat(timelines.get(2).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(8000);
assertThat(timelines.get(3).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(8000);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_noHoldBackInPlaylistAndNoPlaybackSpeedInMediaItem_usesUnitSpeed.
@Test
public void loadLivePlaylist_noHoldBackInPlaylistAndNoPlaybackSpeedInMediaItem_usesUnitSpeed() 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).build()).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(window.liveConfiguration.minPlaybackSpeed).isEqualTo(1f);
assertThat(window.liveConfiguration.maxPlaybackSpeed).isEqualTo(1f);
assertThat(window.defaultPositionUs).isEqualTo(0);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class HlsMediaSourceTest method loadOnDemandPlaylist_withPreciseStartTime_setsDefaultPosition.
@Test
public void loadOnDemandPlaylist_withPreciseStartTime_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,PRECISE=YES" + "#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(15000000);
}
Aggregations