com.google.android.exoplayer.util.LongArray

Here are the examples of the java api class com.google.android.exoplayer.util.LongArray taken from open source projects.

1. SubripParser#parse()

Project: ExoPlayer
Source File: SubripParser.java
View license
@Override
public SubripSubtitle parse(byte[] bytes, int offset, int length) {
    ArrayList<Cue> cues = new ArrayList<>();
    LongArray cueTimesUs = new LongArray();
    ParsableByteArray subripData = new ParsableByteArray(bytes, offset + length);
    subripData.setPosition(offset);
    boolean haveEndTimecode;
    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.
        haveEndTimecode = false;
        currentLine = subripData.readLine();
        Matcher matcher = SUBRIP_TIMING_LINE.matcher(currentLine);
        if (matcher.find()) {
            cueTimesUs.add(parseTimecode(matcher.group(1)));
            String endTimecode = matcher.group(2);
            if (!TextUtils.isEmpty(endTimecode)) {
                haveEndTimecode = true;
                cueTimesUs.add(parseTimecode(matcher.group(2)));
            }
        } 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);
}