Search in sources :

Example 26 with Cue

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

the class WebvttDecoderTest method decodeTypicalWithComments.

@Test
public void decodeTypicalWithComments() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_COMMENTS_FILE);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
    assertThat(subtitle.getEventTime(0)).isEqualTo(0L);
    assertThat(subtitle.getEventTime(0 + 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(2 + 1)).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 27 with Cue

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

the class WebvttDecoderTest method decodeWithBom.

@Test
public void decodeWithBom() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_BOM);
    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 28 with Cue

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

the class WebvttDecoderTest method decodeWithBadCueHeader.

@Test
public void decodeWithBadCueHeader() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_BAD_CUE_HEADER_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(4_000_000L);
    assertThat(subtitle.getEventTime(3)).isEqualTo(5_000_000L);
    Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
    assertThat(secondCue.text.toString()).isEqualTo("This is the third subtitle.");
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

Example 29 with Cue

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

the class WebvttDecoderTest method decodeWithTags.

@Test
public void decodeWithTags() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_TAGS_FILE);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
    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.");
    assertThat(subtitle.getEventTime(4)).isEqualTo(4_000_000L);
    assertThat(subtitle.getEventTime(5)).isEqualTo(5_000_000L);
    Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
    assertThat(thirdCue.text.toString()).isEqualTo("This is the third subtitle.");
    assertThat(subtitle.getEventTime(6)).isEqualTo(6_000_000L);
    assertThat(subtitle.getEventTime(7)).isEqualTo(7_000_000L);
    Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
    assertThat(fourthCue.text.toString()).isEqualTo("This is the <fourth> &subtitle.");
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Test(org.junit.Test)

Example 30 with Cue

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

the class WebvttDecoderTest method decodeWithRubies.

@Test
public void decodeWithRubies() throws Exception {
    WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_RUBIES_FILE);
    assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
    // Check that an explicit `over` position is read from CSS.
    Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
    assertThat(firstCue.text.toString()).isEqualTo("Some text with over-ruby.");
    assertThat((Spanned) firstCue.text).hasRubySpanBetween("Some ".length(), "Some text with over-ruby".length()).withTextAndPosition("over", TextAnnotation.POSITION_BEFORE);
    // Check that `under` is read from CSS and unspecified defaults to `over`.
    Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
    assertThat(secondCue.text.toString()).isEqualTo("Some text with under-ruby and over-ruby (default).");
    assertThat((Spanned) secondCue.text).hasRubySpanBetween("Some ".length(), "Some text with under-ruby".length()).withTextAndPosition("under", TextAnnotation.POSITION_AFTER);
    assertThat((Spanned) secondCue.text).hasRubySpanBetween("Some text with under-ruby and ".length(), "Some text with under-ruby and over-ruby (default)".length()).withTextAndPosition("over", TextAnnotation.POSITION_BEFORE);
    // Check many <rt> tags with different positions nested in a single <ruby> span.
    Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
    assertThat(thirdCue.text.toString()).isEqualTo("base1base2base3.");
    assertThat((Spanned) thirdCue.text).hasRubySpanBetween(/* start= */
    0, "base1".length()).withTextAndPosition("over1", TextAnnotation.POSITION_BEFORE);
    assertThat((Spanned) thirdCue.text).hasRubySpanBetween("base1".length(), "base1base2".length()).withTextAndPosition("under2", TextAnnotation.POSITION_AFTER);
    assertThat((Spanned) thirdCue.text).hasRubySpanBetween("base1base2".length(), "base1base2base3".length()).withTextAndPosition("under3", TextAnnotation.POSITION_AFTER);
    // Check a <ruby> span with no <rt> tags.
    Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
    assertThat(fourthCue.text.toString()).isEqualTo("Some text with no ruby text.");
    assertThat((Spanned) fourthCue.text).hasNoSpans();
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) Spanned(android.text.Spanned) 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