Search in sources :

Example 1 with Subtitle

use of com.google.android.exoplayer2.text.Subtitle 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 Subtitle

use of com.google.android.exoplayer2.text.Subtitle 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 Subtitle

use of com.google.android.exoplayer2.text.Subtitle 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 Subtitle

use of com.google.android.exoplayer2.text.Subtitle 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 Subtitle

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

the class Mp4WebvttDecoderTest method testNoCueSample.

public void testNoCueSample() throws SubtitleDecoderException {
    Mp4WebvttDecoder decoder = new Mp4WebvttDecoder();
    Subtitle result = decoder.decode(NO_CUE_SAMPLE, NO_CUE_SAMPLE.length);
    assertMp4WebvttSubtitleEquals(result);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle)

Aggregations

Cue (com.google.android.exoplayer2.text.Cue)10 SpannableStringBuilder (android.text.SpannableStringBuilder)5 Subtitle (com.google.android.exoplayer2.text.Subtitle)4 Format (com.google.android.exoplayer2.Format)1 ParserException (com.google.android.exoplayer2.ParserException)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 HlsMasterPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist)1 HlsUrl (com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl)1 SubtitleInputBuffer (com.google.android.exoplayer2.text.SubtitleInputBuffer)1 SubtitleOutputBuffer (com.google.android.exoplayer2.text.SubtitleOutputBuffer)1 ArrayList (java.util.ArrayList)1