Search in sources :

Example 56 with Cue

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

the class SsaDecoderTest method decodeTypical.

@Test
public void decodeTypical() throws IOException {
    SsaDecoder decoder = new SsaDecoder();
    byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL);
    Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
    // Check position, line, anchors & alignment are set from Alignment Style (2 - bottom-center).
    Cue firstCue = subtitle.getCues(subtitle.getEventTime(0)).get(0);
    assertWithMessage("Cue.textAlignment").that(firstCue.textAlignment).isEqualTo(Layout.Alignment.ALIGN_CENTER);
    assertWithMessage("Cue.positionAnchor").that(firstCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
    assertThat(firstCue.position).isEqualTo(0.5f);
    assertThat(firstCue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_END);
    assertThat(firstCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
    assertThat(firstCue.line).isEqualTo(0.95f);
    assertTypicalCue1(subtitle, 0);
    assertTypicalCue2(subtitle, 2);
    assertTypicalCue3(subtitle, 4);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle) Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

Example 57 with Cue

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

the class SsaDecoderTest method decodeInvalidPositions.

@Test
public void decodeInvalidPositions() throws IOException {
    SsaDecoder decoder = new SsaDecoder();
    byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), INVALID_POSITIONS);
    Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
    // Negative parameter to \pos() - fall back to the positions implied by middle-left alignment.
    Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
    assertThat(firstCue.position).isEqualTo(0.05f);
    assertThat(firstCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
    assertThat(firstCue.line).isEqualTo(0.5f);
    // Negative parameter to \move() - fall back to the positions implied by middle-left alignment.
    Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
    assertThat(secondCue.position).isEqualTo(0.05f);
    assertThat(secondCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
    assertThat(secondCue.line).isEqualTo(0.5f);
    // Check invalid alignment override (11) is skipped and style-provided one is used (4).
    Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
    assertWithMessage("Cue.positionAnchor").that(thirdCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
    assertThat(thirdCue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
    assertWithMessage("Cue.textAlignment").that(thirdCue.textAlignment).isEqualTo(Layout.Alignment.ALIGN_NORMAL);
    // No braces - fall back to the positions implied by middle-left alignment
    Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
    assertThat(fourthCue.position).isEqualTo(0.05f);
    assertThat(fourthCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
    assertThat(fourthCue.line).isEqualTo(0.5f);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle) Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

Example 58 with Cue

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

the class SsaDecoderTest method decodeInvalidTimecodes.

@Test
public void decodeInvalidTimecodes() throws IOException {
    // Parsing should succeed, parsing the third cue only.
    SsaDecoder decoder = new SsaDecoder();
    byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), INVALID_TIMECODES);
    Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
    assertTypicalCue3(subtitle, 0);
}
Also used : Subtitle(com.google.android.exoplayer2.text.Subtitle) Test(org.junit.Test)

Example 59 with Cue

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

the class TtmlDecoderTest method getOnlyCueTextAtTimeUs.

private static Spanned getOnlyCueTextAtTimeUs(Subtitle subtitle, long timeUs) {
    Cue cue = getOnlyCueAtTimeUs(subtitle, timeUs);
    assertThat(cue.text).isInstanceOf(Spanned.class);
    return (Spanned) Assertions.checkNotNull(cue.text);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Spanned(android.text.Spanned)

Example 60 with Cue

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

the class TtmlDecoderTest method multipleRegions.

@Test
public void multipleRegions() throws IOException, SubtitleDecoderException {
    TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
    List<Cue> cues = subtitle.getCues(1_000_000);
    assertThat(cues).hasSize(2);
    Cue cue = cues.get(0);
    assertThat(cue.text.toString()).isEqualTo("lorem");
    assertThat(cue.position).isEqualTo(10f / 100f);
    assertThat(cue.line).isEqualTo(10f / 100f);
    assertThat(cue.size).isEqualTo(20f / 100f);
    cue = cues.get(1);
    assertThat(cue.text.toString()).isEqualTo("amet");
    assertThat(cue.position).isEqualTo(60f / 100f);
    assertThat(cue.line).isEqualTo(10f / 100f);
    assertThat(cue.size).isEqualTo(20f / 100f);
    cue = getOnlyCueAtTimeUs(subtitle, 5_000_000);
    assertThat(cue.text.toString()).isEqualTo("ipsum");
    assertThat(cue.position).isEqualTo(40f / 100f);
    assertThat(cue.line).isEqualTo(40f / 100f);
    assertThat(cue.size).isEqualTo(20f / 100f);
    cue = getOnlyCueAtTimeUs(subtitle, 9_000_000);
    assertThat(cue.text.toString()).isEqualTo("dolor");
    assertThat(cue.position).isEqualTo(Cue.DIMEN_UNSET);
    assertThat(cue.line).isEqualTo(Cue.DIMEN_UNSET);
    assertThat(cue.size).isEqualTo(Cue.DIMEN_UNSET);
    // TODO: Should be as below, once https://github.com/google/ExoPlayer/issues/2953 is fixed.
    // assertEquals(10f / 100f, cue.position);
    // assertEquals(80f / 100f, cue.line);
    // assertEquals(1f, cue.size);
    cue = getOnlyCueAtTimeUs(subtitle, 21_000_000);
    assertThat(cue.text.toString()).isEqualTo("They first said this");
    assertThat(cue.position).isEqualTo(45f / 100f);
    assertThat(cue.line).isEqualTo(45f / 100f);
    assertThat(cue.size).isEqualTo(35f / 100f);
    cue = getOnlyCueAtTimeUs(subtitle, 25_000_000);
    assertThat(cue.text.toString()).isEqualTo("They first said this\nThen this");
    cue = getOnlyCueAtTimeUs(subtitle, 29_000_000);
    assertThat(cue.text.toString()).isEqualTo("They first said this\nThen this\nFinally this");
    assertThat(cue.position).isEqualTo(45f / 100f);
    assertThat(cue.line).isEqualTo(45f / 100f);
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

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