use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SsaDecoderTest method decodePositionsWithMissingPlayResY.
@Test
public void decodePositionsWithMissingPlayResY() throws IOException {
SsaDecoder decoder = new SsaDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), POSITIONS_WITHOUT_PLAYRES);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
// The dialogue line has a valid \pos() override, but it's ignored because PlayResY isn't
// set (so we don't know the denominator).
Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
assertThat(firstCue.position).isEqualTo(Cue.DIMEN_UNSET);
assertThat(firstCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
assertThat(firstCue.line).isEqualTo(Cue.DIMEN_UNSET);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SsaDecoderTest method decodeEmptyStyleLine.
@Test
public void decodeEmptyStyleLine() throws IOException {
SsaDecoder decoder = new SsaDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), EMPTY_STYLE_LINE);
Subtitle subtitle = decoder.decode(bytes, bytes.length, /* reset= */
false);
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
Cue cue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
SpannedSubject.assertThat((Spanned) cue.text).hasNoSpans();
assertThat(cue.textSize).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.textSizeType).isEqualTo(Cue.TYPE_UNSET);
assertThat(cue.textAlignment).isNull();
assertThat(cue.positionAnchor).isEqualTo(Cue.TYPE_UNSET);
assertThat(cue.position).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.size).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.lineAnchor).isEqualTo(Cue.TYPE_UNSET);
assertThat(cue.line).isEqualTo(Cue.DIMEN_UNSET);
assertThat(cue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SsaDecoderTest method decodePositions.
@Test
public void decodePositions() throws IOException {
SsaDecoder decoder = new SsaDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), POSITIONS);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
// Check \pos() sets position & line
Cue firstCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(0)));
assertThat(firstCue.position).isEqualTo(0.5f);
assertThat(firstCue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
assertThat(firstCue.line).isEqualTo(0.25f);
// Check the \pos() doesn't need to be at the start of the line.
Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
assertThat(secondCue.position).isEqualTo(0.25f);
assertThat(secondCue.line).isEqualTo(0.25f);
// Check only the last \pos() value is used.
Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
assertThat(thirdCue.position).isEqualTo(0.25f);
// Check \move() is treated as \pos()
Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
assertThat(fourthCue.position).isEqualTo(0.5f);
assertThat(fourthCue.line).isEqualTo(0.25f);
// Check alignment override in a separate brace (to bottom-center) affects textAlignment and
// both line & position anchors.
Cue fifthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(8)));
assertThat(fifthCue.position).isEqualTo(0.5f);
assertThat(fifthCue.line).isEqualTo(0.5f);
assertWithMessage("Cue.positionAnchor").that(fifthCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);
assertThat(fifthCue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_END);
assertWithMessage("Cue.textAlignment").that(fifthCue.textAlignment).isEqualTo(Layout.Alignment.ALIGN_CENTER);
// Check alignment override in the same brace (to top-right) affects textAlignment and both line
// & position anchors.
Cue sixthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(10)));
assertThat(sixthCue.position).isEqualTo(0.5f);
assertThat(sixthCue.line).isEqualTo(0.5f);
assertWithMessage("Cue.positionAnchor").that(sixthCue.positionAnchor).isEqualTo(Cue.ANCHOR_TYPE_END);
assertThat(sixthCue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
assertWithMessage("Cue.textAlignment").that(sixthCue.textAlignment).isEqualTo(Layout.Alignment.ALIGN_OPPOSITE);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class Mp4WebvttDecoderTest method singleCueSample.
// Positive tests.
@Test
public void singleCueSample() throws SubtitleDecoderException {
Mp4WebvttDecoder decoder = new Mp4WebvttDecoder();
Subtitle result = decoder.decode(SINGLE_CUE_SAMPLE, SINGLE_CUE_SAMPLE.length, false);
// Line feed must be trimmed by the decoder
Cue expectedCue = WebvttCueParser.newCueForText("Hello World");
assertMp4WebvttSubtitleEquals(result, expectedCue);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class TtmlDecoderTest method shear.
@Test
public void shear() throws IOException, SubtitleDecoderException {
TtmlSubtitle subtitle = getSubtitle(SHEAR_FILE);
Cue firstCue = getOnlyCueAtTimeUs(subtitle, 10_000_000);
assertThat(firstCue.shearDegrees).isZero();
Cue secondCue = getOnlyCueAtTimeUs(subtitle, 20_000_000);
assertThat(secondCue.shearDegrees).isWithin(0.01f).of(-15f);
Cue thirdCue = getOnlyCueAtTimeUs(subtitle, 30_000_000);
assertThat(thirdCue.shearDegrees).isWithin(0.01f).of(15f);
Cue fourthCue = getOnlyCueAtTimeUs(subtitle, 40_000_000);
assertThat(fourthCue.shearDegrees).isWithin(0.01f).of(-15f);
Cue fifthCue = getOnlyCueAtTimeUs(subtitle, 50_000_000);
assertThat(fifthCue.shearDegrees).isWithin(0.01f).of(-22.5f);
Cue sixthCue = getOnlyCueAtTimeUs(subtitle, 60_000_000);
assertThat(sixthCue.shearDegrees).isWithin(0.01f).of(0f);
Cue seventhCue = getOnlyCueAtTimeUs(subtitle, 70_000_000);
assertThat(seventhCue.shearDegrees).isWithin(0.01f).of(-90f);
Cue eighthCue = getOnlyCueAtTimeUs(subtitle, 80_000_000);
assertThat(eighthCue.shearDegrees).isWithin(0.01f).of(90f);
}
Aggregations