Search in sources :

Example 1 with UnrecognizedInputFormatException

use of com.google.android.exoplayer2.source.UnrecognizedInputFormatException 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.");
}
Also used : UnrecognizedInputFormatException(com.google.android.exoplayer2.source.UnrecognizedInputFormatException) ParserException(com.google.android.exoplayer2.ParserException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList)

Aggregations

ParserException (com.google.android.exoplayer2.ParserException)1 UnrecognizedInputFormatException (com.google.android.exoplayer2.source.UnrecognizedInputFormatException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 LinkedList (java.util.LinkedList)1