use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist in project ExoPlayer by google.
the class HlsMediaPlaylistParserTest method variableSubstitution.
@Test
public void variableSubstitution() throws IOException {
Uri playlistUri = Uri.parse("https://example.com/substitution.m3u8");
String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:8\n" + "#EXT-X-DEFINE:NAME=\"underscore_1\",VALUE=\"{\"\n" + "#EXT-X-DEFINE:NAME=\"dash-1\",VALUE=\"replaced_value.ts\"\n" + "#EXT-X-TARGETDURATION:5\n" + "#EXT-X-MEDIA-SEQUENCE:10\n" + "#EXTINF:5.005,\n" + "segment1.ts\n" + "#EXT-X-MAP:URI=\"{$dash-1}\"" + "#EXTINF:5.005,\n" + "segment{$underscore_1}$name_1}\n";
InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
Segment segment = playlist.segments.get(1);
assertThat(segment.initializationSegment.url).isEqualTo("replaced_value.ts");
assertThat(segment.url).isEqualTo("segment{$name_1}");
}
use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist in project ExoPlayer by google.
the class HlsChunkSourceTest method getAdjustedSeekPositionUs_emptyPlaylist.
@Test
public void getAdjustedSeekPositionUs_emptyPlaylist() throws IOException {
InputStream inputStream = TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), PLAYLIST_EMPTY);
HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(PLAYLIST_URI, inputStream);
when(mockPlaylistTracker.getPlaylistSnapshot(eq(PLAYLIST_URI), anyBoolean())).thenReturn(playlist);
long adjustedPositionUs = testChunkSource.getAdjustedSeekPositionUs(playlistTimeToPeriodTimeUs(100_000_000), SeekParameters.EXACT);
assertThat(periodTimeToPlaylistTimeUs(adjustedPositionUs)).isEqualTo(100_000_000);
}
use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist in project ExoPlayer by google.
the class HlsMediaPlaylistSegmentIteratorTest method next_startIteratorAtPartWithinSegment_correctElements.
@Test
public void next_startIteratorAtPartWithinSegment_correctElements() {
HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, /* mediaSequence= */
14, /* partIndex= */
1));
List<DataSpec> datasSpecs = new ArrayList<>();
while (hlsMediaPlaylistSegmentIterator.next()) {
datasSpecs.add(hlsMediaPlaylistSegmentIterator.getDataSpec());
}
assertThat(datasSpecs).hasSize(7);
// The iterator starts with 11 parts.
assertThat(datasSpecs.get(0).uri.toString()).isEqualTo("fileSequence14.1.ts");
assertThat(datasSpecs.get(1).uri.toString()).isEqualTo("fileSequence14.2.ts");
assertThat(datasSpecs.get(2).uri.toString()).isEqualTo("fileSequence14.3.ts");
// Use a segment in between if possible.
assertThat(datasSpecs.get(3).uri.toString()).isEqualTo("fileSequence15.ts");
// Then parts again.
assertThat(datasSpecs.get(4).uri.toString()).isEqualTo("fileSequence16.0.ts");
assertThat(datasSpecs.get(5).uri.toString()).isEqualTo("fileSequence16.1.ts");
assertThat(datasSpecs.get(6).uri.toString()).isEqualTo("fileSequence16.2.ts");
}
use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist in project ExoPlayer by google.
the class HlsMediaPlaylistSegmentIteratorTest method next_startIteratorAtTrailingPart_correctElements.
@Test
public void next_startIteratorAtTrailingPart_correctElements() {
HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, /* mediaSequence= */
16, /* partIndex= */
1));
List<DataSpec> datasSpecs = new ArrayList<>();
while (hlsMediaPlaylistSegmentIterator.next()) {
datasSpecs.add(hlsMediaPlaylistSegmentIterator.getDataSpec());
}
assertThat(datasSpecs).hasSize(2);
// The iterator starts with 2 parts.
assertThat(datasSpecs.get(0).uri.toString()).isEqualTo("fileSequence16.1.ts");
// The preload part is the last.
assertThat(Iterables.getLast(datasSpecs).uri.toString()).isEqualTo("fileSequence16.2.ts");
}
use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist in project ExoPlayer by google.
the class HlsMediaPlaylistSegmentIteratorTest method create_withMediaSequenceBeforeTrailingPartSegment_isEmpty.
@Test
public void create_withMediaSequenceBeforeTrailingPartSegment_isEmpty() {
HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, mediaPlaylist.mediaSequence + mediaPlaylist.segments.size() + 1, /* partIndex= */
C.INDEX_UNSET));
assertThat(hlsMediaPlaylistSegmentIterator.next()).isFalse();
}
Aggregations