Search in sources :

Example 1 with LongArray

use of com.google.android.exoplayer2.util.LongArray in project ExoPlayer by google.

the class MatroskaExtractor method startMasterElement.

/* package */
void startMasterElement(int id, long contentPosition, long contentSize) throws ParserException {
    switch(id) {
        case ID_SEGMENT:
            if (segmentContentPosition != C.POSITION_UNSET && segmentContentPosition != contentPosition) {
                throw new ParserException("Multiple Segment elements not supported");
            }
            segmentContentPosition = contentPosition;
            segmentContentSize = contentSize;
            break;
        case ID_SEEK:
            seekEntryId = UNSET_ENTRY_ID;
            seekEntryPosition = C.POSITION_UNSET;
            break;
        case ID_CUES:
            cueTimesUs = new LongArray();
            cueClusterPositions = new LongArray();
            break;
        case ID_CUE_POINT:
            seenClusterPositionForCurrentCuePoint = false;
            break;
        case ID_CLUSTER:
            if (!sentSeekMap) {
                // We need to build cues before parsing the cluster.
                if (cuesContentPosition != C.POSITION_UNSET) {
                    // We know where the Cues element is located. Seek to request it.
                    seekForCues = true;
                } else {
                    // We don't know where the Cues element is located. It's most likely omitted. Allow
                    // playback, but disable seeking.
                    extractorOutput.seekMap(new SeekMap.Unseekable(durationUs));
                    sentSeekMap = true;
                }
            }
            break;
        case ID_BLOCK_GROUP:
            sampleSeenReferenceBlock = false;
            break;
        case ID_CONTENT_ENCODING:
            // TODO: check and fail if more than one content encoding is present.
            break;
        case ID_CONTENT_ENCRYPTION:
            currentTrack.hasContentEncryption = true;
            break;
        case ID_TRACK_ENTRY:
            currentTrack = new Track();
            break;
        default:
            break;
    }
}
Also used : LongArray(com.google.android.exoplayer2.util.LongArray) ParserException(com.google.android.exoplayer2.ParserException) SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

Example 2 with LongArray

use of com.google.android.exoplayer2.util.LongArray in project ExoPlayer by google.

the class SubripDecoder method decode.

@Override
protected SubripSubtitle decode(byte[] bytes, int length) {
    ArrayList<Cue> cues = new ArrayList<>();
    LongArray cueTimesUs = new LongArray();
    ParsableByteArray subripData = new ParsableByteArray(bytes, length);
    String currentLine;
    while ((currentLine = subripData.readLine()) != null) {
        if (currentLine.length() == 0) {
            // Skip blank lines.
            continue;
        }
        // Parse the index line as a sanity check.
        try {
            Integer.parseInt(currentLine);
        } catch (NumberFormatException e) {
            Log.w(TAG, "Skipping invalid index: " + currentLine);
            continue;
        }
        // Read and parse the timing line.
        boolean haveEndTimecode = false;
        currentLine = subripData.readLine();
        Matcher matcher = SUBRIP_TIMING_LINE.matcher(currentLine);
        if (matcher.matches()) {
            cueTimesUs.add(parseTimecode(matcher, 1));
            if (!TextUtils.isEmpty(matcher.group(6))) {
                haveEndTimecode = true;
                cueTimesUs.add(parseTimecode(matcher, 6));
            }
        } else {
            Log.w(TAG, "Skipping invalid timing: " + currentLine);
            continue;
        }
        // Read and parse the text.
        textBuilder.setLength(0);
        while (!TextUtils.isEmpty(currentLine = subripData.readLine())) {
            if (textBuilder.length() > 0) {
                textBuilder.append("<br>");
            }
            textBuilder.append(currentLine.trim());
        }
        Spanned text = Html.fromHtml(textBuilder.toString());
        cues.add(new Cue(text));
        if (haveEndTimecode) {
            cues.add(null);
        }
    }
    Cue[] cuesArray = new Cue[cues.size()];
    cues.toArray(cuesArray);
    long[] cueTimesUsArray = cueTimesUs.toArray();
    return new SubripSubtitle(cuesArray, cueTimesUsArray);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Spanned(android.text.Spanned) LongArray(com.google.android.exoplayer2.util.LongArray) ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) Cue(com.google.android.exoplayer2.text.Cue)

Aggregations

LongArray (com.google.android.exoplayer2.util.LongArray)2 Spanned (android.text.Spanned)1 ParserException (com.google.android.exoplayer2.ParserException)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 Cue (com.google.android.exoplayer2.text.Cue)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1