public void testParsingByteOrderMark() { using (Stream inputStream = wrapWithByteOrderMark(TestUtil.inputStreamFromResource("simpleMediaPlaylist.m3u8"))) { PlaylistParser playlistParser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8); Playlist playlist = playlistParser.parse(); Assert.Equal(10, playlist.getMediaPlaylist().getTargetDuration()); } }
Playlist readPlaylist(String fileName) { Assert.NotNull(fileName); using (Stream ins = new FileStream("resources/" + fileName, FileMode.Open)) { Playlist playlist = new PlaylistParser(ins, Format.EXT_M3U, Encoding.UTF_8).parse(); return(playlist); } }
public void testParsingMultiplePlaylists() { using (Stream inputStream = TestUtil.inputStreamFromResource("twoMediaPlaylists.m3u8")) { PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8); Assert.True(parser.isAvailable()); Playlist playlist1 = parser.parse(); Assert.True(parser.isAvailable()); Playlist playlist2 = parser.parse(); Assert.False(parser.isAvailable()); List <TrackData> expected1 = new List <TrackData>() { makeTrackData("http://media.example.com/first.ts", 9.009f), makeTrackData("http://media.example.com/second.ts", 9.009f), makeTrackData("http://media.example.com/third.ts", 3.003f) }; var actual1 = playlist1.getMediaPlaylist().getTracks(); Assert.Equal( expected1, actual1); Assert.Equal( new List <TrackData>() { makeTrackData("http://media.example.com/fourth.ts", 9.01f), makeTrackData("http://media.example.com/fifth.ts", 9.011f) }, playlist2.getMediaPlaylist().getTracks()); // Assert.Equal(0, inputStream.available()); // TODO: Why? And what's the c# equivalent } }
public void testWritingByteOrderMark() { Playlist playlist1 = null; Playlist playlist2 = null; String written = String.Empty; using (Stream inputStream = TestUtil.inputStreamFromResource("simpleMediaPlaylist.m3u8")) { playlist1 = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8).parse(); } using (var os = new MemoryStream()) { PlaylistWriter writer = new PlaylistWriter.Builder() .withOutputStream(os) .withFormat(Format.EXT_M3U) .withEncoding(Encoding.UTF_8) .useByteOrderMark() .build(); writer.write(playlist1); // written = os.ToString(Encoding.UTF_8.value); os.Position = 0; using (var sr = new StreamReader(os, System.Text.Encoding.UTF8)) written = sr.ReadToEnd(); } Assert.Equal(Constants.UNICODE_BOM, written[0]); using (Stream inputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(written))) { playlist2 = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8).parse(); } Assert.Equal(playlist1, playlist2); }
public void testAllowNegativeNumbersValidation() { Playlist playlist = null; bool found = false; try { Stream inputStream = TestUtil.inputStreamFromResource("negativeDurationMediaPlaylist.m3u8"); new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8).parse(); } catch (PlaylistException exception) { found = exception.getErrors().Contains(PlaylistError.TRACK_INFO_WITH_NEGATIVE_DURATION); } Assert.True(found); using (Stream inputStream = TestUtil.inputStreamFromResource("negativeDurationMediaPlaylist.m3u8")) { playlist = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT).parse(); } Assert.Equal(-1f, playlist.getMediaPlaylist().getTracks()[0].getTrackInfo().duration); }