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.");
}
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.");
}
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.");
}
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.");
}
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();
}
Aggregations