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