use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class HlsPlaylistParser method parse.
@Override
public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
Queue<String> extraLines = new LinkedList<>();
String line;
try {
if (!checkPlaylistHeader(reader)) {
throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.", uri);
}
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
// Do nothing.
} else if (line.startsWith(TAG_STREAM_INF)) {
extraLines.add(line);
return parseMasterPlaylist(new LineIterator(extraLines, reader), uri.toString());
} else if (line.startsWith(TAG_TARGET_DURATION) || line.startsWith(TAG_MEDIA_SEQUENCE) || line.startsWith(TAG_MEDIA_DURATION) || line.startsWith(TAG_KEY) || line.startsWith(TAG_BYTERANGE) || line.equals(TAG_DISCONTINUITY) || line.equals(TAG_DISCONTINUITY_SEQUENCE) || line.equals(TAG_ENDLIST)) {
extraLines.add(line);
return parseMediaPlaylist(new LineIterator(extraLines, reader), uri.toString());
} else {
extraLines.add(line);
}
}
} finally {
Util.closeQuietly(reader);
}
throw new ParserException("Failed to parse the playlist, could not identify any tags.");
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method testReadCommentHeader.
public void testReadCommentHeader() throws ParserException {
byte[] data = TestData.getCommentHeaderDataUTF8();
ParsableByteArray headerData = new ParsableByteArray(data, data.length);
VorbisUtil.CommentHeader commentHeader = VorbisUtil.readVorbisCommentHeader(headerData);
assertEquals("Xiph.Org libVorbis I 20120203 (Omnipresent)", commentHeader.vendor);
assertEquals(3, commentHeader.comments.length);
assertEquals("ALBUM=รครถ", commentHeader.comments[0]);
assertEquals("TITLE=A sample song", commentHeader.comments[1]);
assertEquals("ARTIST=Google", commentHeader.comments[2]);
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidPattern.
public void testVerifyVorbisHeaderCapturePatternInvalidPattern() {
ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's' });
try {
VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false);
fail();
} catch (ParserException e) {
assertEquals("expected characters 'vorbis'", e.getMessage());
}
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite.
public void testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite() throws ParserException {
ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'v', 'o', 'r', 'b', 'i', 's' });
assertFalse(VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, true));
}
use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.
the class WavExtractor method read.
@Override
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException {
if (wavHeader == null) {
wavHeader = WavHeaderReader.peek(input);
if (wavHeader == null) {
// Should only happen if the media wasn't sniffed.
throw new ParserException("Unsupported or unrecognized wav header.");
}
Format format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null, wavHeader.getBitrate(), MAX_INPUT_SIZE, wavHeader.getNumChannels(), wavHeader.getSampleRateHz(), wavHeader.getEncoding(), null, null, 0, null);
trackOutput.format(format);
bytesPerFrame = wavHeader.getBytesPerFrame();
}
if (!wavHeader.hasDataBounds()) {
WavHeaderReader.skipToData(input, wavHeader);
extractorOutput.seekMap(this);
}
int bytesAppended = trackOutput.sampleData(input, MAX_INPUT_SIZE - pendingBytes, true);
if (bytesAppended != RESULT_END_OF_INPUT) {
pendingBytes += bytesAppended;
}
// Samples must consist of a whole number of frames.
int pendingFrames = pendingBytes / bytesPerFrame;
if (pendingFrames > 0) {
long timeUs = wavHeader.getTimeUs(input.getPosition() - pendingBytes);
int size = pendingFrames * bytesPerFrame;
pendingBytes -= size;
trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, size, pendingBytes, null);
}
return bytesAppended == RESULT_END_OF_INPUT ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
}
Aggregations