Search in sources :

Example 1 with Cue

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

the class TtmlDecoderTest method testFontSizeSpans.

public void testFontSizeSpans() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_TTML_FILE);
    assertEquals(10, subtitle.getEventTimeCount());
    List<Cue> cues = subtitle.getCues(10 * 1000000);
    assertEquals(1, cues.size());
    SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("text 1", String.valueOf(spannable));
    assertAbsoluteFontSize(spannable, 32);
    cues = subtitle.getCues(20 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("text 2", String.valueOf(cues.get(0).text));
    assertRelativeFontSize(spannable, 2.2f);
    cues = subtitle.getCues(30 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("text 3", String.valueOf(cues.get(0).text));
    assertRelativeFontSize(spannable, 1.5f);
    cues = subtitle.getCues(40 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("two values", String.valueOf(cues.get(0).text));
    assertAbsoluteFontSize(spannable, 16);
    cues = subtitle.getCues(50 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("leading dot", String.valueOf(cues.get(0).text));
    assertRelativeFontSize(spannable, 0.5f);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with Cue

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

the class TtmlDecoderTest method testFontSizeWithEmptyValueIsIgnored.

public void testFontSizeWithEmptyValueIsIgnored() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_EMPTY_TTML_FILE);
    assertEquals(2, subtitle.getEventTimeCount());
    List<Cue> cues = subtitle.getCues(10 * 1000000);
    assertEquals(1, cues.size());
    SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("empty", String.valueOf(spannable));
    assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
    assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 3 with Cue

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

the class TtmlDecoderTest method testFontSizeWithMissingUnitIsIgnored.

public void testFontSizeWithMissingUnitIsIgnored() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_MISSING_UNIT_TTML_FILE);
    assertEquals(2, subtitle.getEventTimeCount());
    List<Cue> cues = subtitle.getCues(10 * 1000000);
    assertEquals(1, cues.size());
    SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("no unit", String.valueOf(spannable));
    assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
    assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 4 with Cue

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

the class Mp4WebvttDecoderTest method testSingleCueSample.

// Positive tests.
public void testSingleCueSample() throws SubtitleDecoderException {
    Mp4WebvttDecoder decoder = new Mp4WebvttDecoder();
    Subtitle result = decoder.decode(SINGLE_CUE_SAMPLE, SINGLE_CUE_SAMPLE.length);
    // Line feed must be trimmed by the decoder
    Cue expectedCue = new Cue("Hello World");
    assertMp4WebvttSubtitleEquals(result, expectedCue);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle) Cue(com.google.android.exoplayer2.text.Cue)

Example 5 with Cue

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

the class Tx3gDecoder method decode.

@Override
protected Subtitle decode(byte[] bytes, int length) {
    parsableByteArray.reset(bytes, length);
    int textLength = parsableByteArray.readUnsignedShort();
    if (textLength == 0) {
        return Tx3gSubtitle.EMPTY;
    }
    String cueText = parsableByteArray.readString(textLength);
    return new Tx3gSubtitle(new Cue(cueText));
}
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