Search in sources :

Example 11 with HlsPlaylistParser

use of com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser 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}");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Segment(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment) Test(org.junit.Test)

Example 12 with HlsPlaylistParser

use of com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser 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);
}
Also used : InputStream(java.io.InputStream) HlsPlaylistParser(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)12 Uri (android.net.Uri)10 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)8 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)3 HlsPlaylistParser (com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser)3 Nullable (androidx.annotation.Nullable)2 Format (com.google.android.exoplayer2.Format)1 ParserException (com.google.android.exoplayer2.ParserException)1 HlsPlaylistTracker (com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker)1 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)1 IOException (java.io.IOException)1 Before (org.junit.Before)1