Search in sources :

Example 31 with Cue

use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.

the class WebvttDecoderTest method decodeTypical.

@Test
public void decodeTypical() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_FILE);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
    assertThat(subtitle.getEventTime(0)).isEqualTo(0L);
    assertThat(subtitle.getEventTime(1)).isEqualTo(1_234_000L);
    Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
    assertThat(firstCue.text.toString()).isEqualTo("This is the first subtitle.");
    assertThat(subtitle.getEventTime(2)).isEqualTo(2_345_000L);
    assertThat(subtitle.getEventTime(3)).isEqualTo(3_456_000L);
    Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
    assertThat(secondCue.text.toString()).isEqualTo("This is the second subtitle.");
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

Example 32 with Cue

use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.

the class PlaybackOutput method dumpSubtitles.

private void dumpSubtitles(Dumper dumper) {
    if (subtitles.isEmpty()) {
        return;
    }
    dumper.startBlock("TextOutput");
    for (int i = 0; i < subtitles.size(); i++) {
        dumper.startBlock("Subtitle[" + i + "]");
        List<Cue> subtitle = subtitles.get(i);
        if (subtitle.isEmpty()) {
            dumper.add("Cues", ImmutableList.of());
        }
        for (int j = 0; j < subtitle.size(); j++) {
            dumper.startBlock("Cue[" + j + "]");
            Cue cue = subtitle.get(j);
            dumpIfNotEqual(dumper, "text", cue.text, null);
            dumpIfNotEqual(dumper, "textAlignment", cue.textAlignment, null);
            dumpBitmap(dumper, cue.bitmap);
            dumpIfNotEqual(dumper, "line", cue.line, Cue.DIMEN_UNSET);
            dumpIfNotEqual(dumper, "lineType", cue.lineType, Cue.TYPE_UNSET);
            dumpIfNotEqual(dumper, "lineAnchor", cue.lineAnchor, Cue.TYPE_UNSET);
            dumpIfNotEqual(dumper, "position", cue.position, Cue.DIMEN_UNSET);
            dumpIfNotEqual(dumper, "positionAnchor", cue.positionAnchor, Cue.TYPE_UNSET);
            dumpIfNotEqual(dumper, "size", cue.size, Cue.DIMEN_UNSET);
            dumpIfNotEqual(dumper, "bitmapHeight", cue.bitmapHeight, Cue.DIMEN_UNSET);
            if (cue.windowColorSet) {
                dumper.add("cue.windowColor", cue.windowColor);
            }
            dumpIfNotEqual(dumper, "textSizeType", cue.textSizeType, Cue.TYPE_UNSET);
            dumpIfNotEqual(dumper, "textSize", cue.textSize, Cue.DIMEN_UNSET);
            dumpIfNotEqual(dumper, "verticalType", cue.verticalType, Cue.TYPE_UNSET);
            dumper.endBlock();
        }
        dumper.endBlock();
    }
    dumper.endBlock();
}
Also used : Cue(com.google.android.exoplayer2.text.Cue)

Example 33 with Cue

use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.

the class WebvttDecoderTest method assertCue.

private static void assertCue(WebvttSubtitle subtitle, int eventTimeIndex, long startTimeUs, int endTimeUs, String text, Alignment textAlignment, float line, int lineType, int lineAnchor, float position, int positionAnchor, float size) {
    assertEquals(startTimeUs, subtitle.getEventTime(eventTimeIndex));
    assertEquals(endTimeUs, subtitle.getEventTime(eventTimeIndex + 1));
    List<Cue> cues = subtitle.getCues(subtitle.getEventTime(eventTimeIndex));
    assertEquals(1, cues.size());
    // Assert cue properties.
    Cue cue = cues.get(0);
    assertEquals(text, cue.text.toString());
    assertEquals(textAlignment, cue.textAlignment);
    assertEquals(line, cue.line);
    assertEquals(lineType, cue.lineType);
    assertEquals(lineAnchor, cue.lineAnchor);
    assertEquals(position, cue.position);
    assertEquals(positionAnchor, cue.positionAnchor);
    assertEquals(size, cue.size);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue)

Example 34 with Cue

use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.

the class TtmlDecoderTest method assertSpans.

private void assertSpans(TtmlSubtitle subtitle, int second, String text, String font, int fontStyle, int backgroundColor, int color, boolean isUnderline, boolean isLinethrough, Layout.Alignment alignment) {
    long timeUs = second * 1000000;
    List<Cue> cues = subtitle.getCues(timeUs);
    assertEquals(1, cues.size());
    assertEquals(text, String.valueOf(cues.get(0).text));
    assertEquals("single cue expected for timeUs: " + timeUs, 1, cues.size());
    SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
    assertFont(spannable, font);
    assertStyle(spannable, fontStyle);
    assertUnderline(spannable, isUnderline);
    assertStrikethrough(spannable, isLinethrough);
    assertUnderline(spannable, isUnderline);
    assertBackground(spannable, backgroundColor);
    assertForeground(spannable, color);
    assertAlignment(spannable, alignment);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 35 with Cue

use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.

the class TtmlDecoderTest method testMultipleRegions.

public void testMultipleRegions() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
    List<Cue> output = subtitle.getCues(1000000);
    assertEquals(2, output.size());
    Cue ttmlCue = output.get(0);
    assertEquals("lorem", ttmlCue.text.toString());
    assertEquals(10.f / 100.f, ttmlCue.position);
    assertEquals(10.f / 100.f, ttmlCue.line);
    assertEquals(20.f / 100.f, ttmlCue.size);
    ttmlCue = output.get(1);
    assertEquals("amet", ttmlCue.text.toString());
    assertEquals(60.f / 100.f, ttmlCue.position);
    assertEquals(10.f / 100.f, ttmlCue.line);
    assertEquals(20.f / 100.f, ttmlCue.size);
    output = subtitle.getCues(5000000);
    assertEquals(1, output.size());
    ttmlCue = output.get(0);
    assertEquals("ipsum", ttmlCue.text.toString());
    assertEquals(40.f / 100.f, ttmlCue.position);
    assertEquals(40.f / 100.f, ttmlCue.line);
    assertEquals(20.f / 100.f, ttmlCue.size);
    output = subtitle.getCues(9000000);
    assertEquals(1, output.size());
    ttmlCue = output.get(0);
    assertEquals("dolor", ttmlCue.text.toString());
    assertEquals(10.f / 100.f, ttmlCue.position);
    assertEquals(80.f / 100.f, ttmlCue.line);
    assertEquals(Cue.DIMEN_UNSET, ttmlCue.size);
    output = subtitle.getCues(21000000);
    assertEquals(1, output.size());
    ttmlCue = output.get(0);
    assertEquals("She first said this", ttmlCue.text.toString());
    assertEquals(45.f / 100.f, ttmlCue.position);
    assertEquals(45.f / 100.f, ttmlCue.line);
    assertEquals(35.f / 100.f, ttmlCue.size);
    output = subtitle.getCues(25000000);
    ttmlCue = output.get(0);
    assertEquals("She first said this\nThen this", ttmlCue.text.toString());
    output = subtitle.getCues(29000000);
    assertEquals(1, output.size());
    ttmlCue = output.get(0);
    assertEquals("She first said this\nThen this\nFinally this", ttmlCue.text.toString());
    assertEquals(45.f / 100.f, ttmlCue.position);
    assertEquals(45.f / 100.f, ttmlCue.line);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue)

Aggregations

Cue (com.google.android.exoplayer2.text.Cue)58 Test (org.junit.Test)40 Subtitle (com.google.android.exoplayer2.text.Subtitle)13 ArrayList (java.util.ArrayList)12 Nullable (androidx.annotation.Nullable)10 Spanned (android.text.Spanned)8 SpannableStringBuilder (android.text.SpannableStringBuilder)7 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)5 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)4 SpannableString (android.text.SpannableString)3 UnderlineSpan (android.text.style.UnderlineSpan)3 Format (com.google.android.exoplayer2.Format)3 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)3 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)3 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)3 HorizontalTextInVerticalContextSpan (com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan)3 RubySpan (com.google.android.exoplayer2.text.span.RubySpan)3 TextEmphasisSpan (com.google.android.exoplayer2.text.span.TextEmphasisSpan)3 WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)3 Matcher (java.util.regex.Matcher)3