Search in sources :

Example 6 with Subtitle

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

Example 7 with Subtitle

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

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

Example 9 with Subtitle

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

the class TtmlDecoderTest method testFontSizeWithInvalidValueIsIgnored.

public void testFontSizeWithInvalidValueIsIgnored() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_INVALID_TTML_FILE);
    assertEquals(6, subtitle.getEventTimeCount());
    List<Cue> cues = subtitle.getCues(10 * 1000000);
    assertEquals(1, cues.size());
    SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("invalid", String.valueOf(spannable));
    assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
    assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
    cues = subtitle.getCues(20 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("invalid", String.valueOf(spannable));
    assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
    assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
    cues = subtitle.getCues(30 * 1000000);
    assertEquals(1, cues.size());
    spannable = (SpannableStringBuilder) cues.get(0).text;
    assertEquals("invalid dot", 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 10 with Subtitle

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

the class Mp4WebvttDecoderTest method testTwoCuesSample.

public void testTwoCuesSample() throws SubtitleDecoderException {
    Mp4WebvttDecoder decoder = new Mp4WebvttDecoder();
    Subtitle result = decoder.decode(DOUBLE_CUE_SAMPLE, DOUBLE_CUE_SAMPLE.length);
    Cue firstExpectedCue = new Cue("Hello World");
    Cue secondExpectedCue = new Cue("Bye Bye");
    assertMp4WebvttSubtitleEquals(result, firstExpectedCue, secondExpectedCue);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle) Cue(com.google.android.exoplayer2.text.Cue)

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