Search in sources :

Example 36 with HlsMediaPlaylist

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}");
}
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 37 with HlsMediaPlaylist

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

Example 38 with HlsMediaPlaylist

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");
}
Also used : ArrayList(java.util.ArrayList) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Example 39 with HlsMediaPlaylist

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");
}
Also used : ArrayList(java.util.ArrayList) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Example 40 with HlsMediaPlaylist

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

Aggregations

HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)20 Uri (android.net.Uri)18 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)18 Test (org.junit.Test)18 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)11 Nullable (androidx.annotation.Nullable)9 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 HlsPlaylistParser (com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser)4 IOException (java.io.IOException)3 ParserException (com.google.android.exoplayer2.ParserException)2 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)2 BaseMediaChunkIterator (com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator)2 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 SystemClock (android.os.SystemClock)1 Pair (android.util.Pair)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1