use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class WebvttDecoderTest method decodeTypical.
@Test
public void decodeTypical() throws Exception {
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_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(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 PlaybackOutput method dumpSubtitles.
private void dumpSubtitles(Dumper dumper) {
if (subtitles.isEmpty()) {
return;
}
dumper.startBlock("TextOutput");
for (int i = 0; i < subtitles.size(); i++) {
dumper.startBlock("Subtitle[" + i + "]");
List<Cue> subtitle = subtitles.get(i);
if (subtitle.isEmpty()) {
dumper.add("Cues", ImmutableList.of());
}
for (int j = 0; j < subtitle.size(); j++) {
dumper.startBlock("Cue[" + j + "]");
Cue cue = subtitle.get(j);
dumpIfNotEqual(dumper, "text", cue.text, null);
dumpIfNotEqual(dumper, "textAlignment", cue.textAlignment, null);
dumpBitmap(dumper, cue.bitmap);
dumpIfNotEqual(dumper, "line", cue.line, Cue.DIMEN_UNSET);
dumpIfNotEqual(dumper, "lineType", cue.lineType, Cue.TYPE_UNSET);
dumpIfNotEqual(dumper, "lineAnchor", cue.lineAnchor, Cue.TYPE_UNSET);
dumpIfNotEqual(dumper, "position", cue.position, Cue.DIMEN_UNSET);
dumpIfNotEqual(dumper, "positionAnchor", cue.positionAnchor, Cue.TYPE_UNSET);
dumpIfNotEqual(dumper, "size", cue.size, Cue.DIMEN_UNSET);
dumpIfNotEqual(dumper, "bitmapHeight", cue.bitmapHeight, Cue.DIMEN_UNSET);
if (cue.windowColorSet) {
dumper.add("cue.windowColor", cue.windowColor);
}
dumpIfNotEqual(dumper, "textSizeType", cue.textSizeType, Cue.TYPE_UNSET);
dumpIfNotEqual(dumper, "textSize", cue.textSize, Cue.DIMEN_UNSET);
dumpIfNotEqual(dumper, "verticalType", cue.verticalType, Cue.TYPE_UNSET);
dumper.endBlock();
}
dumper.endBlock();
}
dumper.endBlock();
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class WebvttDecoderTest method assertCue.
private static void assertCue(WebvttSubtitle subtitle, int eventTimeIndex, long startTimeUs, int endTimeUs, String text, Alignment textAlignment, float line, int lineType, int lineAnchor, float position, int positionAnchor, float size) {
assertEquals(startTimeUs, subtitle.getEventTime(eventTimeIndex));
assertEquals(endTimeUs, subtitle.getEventTime(eventTimeIndex + 1));
List<Cue> cues = subtitle.getCues(subtitle.getEventTime(eventTimeIndex));
assertEquals(1, cues.size());
// Assert cue properties.
Cue cue = cues.get(0);
assertEquals(text, cue.text.toString());
assertEquals(textAlignment, cue.textAlignment);
assertEquals(line, cue.line);
assertEquals(lineType, cue.lineType);
assertEquals(lineAnchor, cue.lineAnchor);
assertEquals(position, cue.position);
assertEquals(positionAnchor, cue.positionAnchor);
assertEquals(size, cue.size);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class TtmlDecoderTest method assertSpans.
private void assertSpans(TtmlSubtitle subtitle, int second, String text, String font, int fontStyle, int backgroundColor, int color, boolean isUnderline, boolean isLinethrough, Layout.Alignment alignment) {
long timeUs = second * 1000000;
List<Cue> cues = subtitle.getCues(timeUs);
assertEquals(1, cues.size());
assertEquals(text, String.valueOf(cues.get(0).text));
assertEquals("single cue expected for timeUs: " + timeUs, 1, cues.size());
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
assertFont(spannable, font);
assertStyle(spannable, fontStyle);
assertUnderline(spannable, isUnderline);
assertStrikethrough(spannable, isLinethrough);
assertUnderline(spannable, isUnderline);
assertBackground(spannable, backgroundColor);
assertForeground(spannable, color);
assertAlignment(spannable, alignment);
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class TtmlDecoderTest method testMultipleRegions.
public void testMultipleRegions() throws IOException, SubtitleDecoderException {
TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
List<Cue> output = subtitle.getCues(1000000);
assertEquals(2, output.size());
Cue ttmlCue = output.get(0);
assertEquals("lorem", ttmlCue.text.toString());
assertEquals(10.f / 100.f, ttmlCue.position);
assertEquals(10.f / 100.f, ttmlCue.line);
assertEquals(20.f / 100.f, ttmlCue.size);
ttmlCue = output.get(1);
assertEquals("amet", ttmlCue.text.toString());
assertEquals(60.f / 100.f, ttmlCue.position);
assertEquals(10.f / 100.f, ttmlCue.line);
assertEquals(20.f / 100.f, ttmlCue.size);
output = subtitle.getCues(5000000);
assertEquals(1, output.size());
ttmlCue = output.get(0);
assertEquals("ipsum", ttmlCue.text.toString());
assertEquals(40.f / 100.f, ttmlCue.position);
assertEquals(40.f / 100.f, ttmlCue.line);
assertEquals(20.f / 100.f, ttmlCue.size);
output = subtitle.getCues(9000000);
assertEquals(1, output.size());
ttmlCue = output.get(0);
assertEquals("dolor", ttmlCue.text.toString());
assertEquals(10.f / 100.f, ttmlCue.position);
assertEquals(80.f / 100.f, ttmlCue.line);
assertEquals(Cue.DIMEN_UNSET, ttmlCue.size);
output = subtitle.getCues(21000000);
assertEquals(1, output.size());
ttmlCue = output.get(0);
assertEquals("She first said this", ttmlCue.text.toString());
assertEquals(45.f / 100.f, ttmlCue.position);
assertEquals(45.f / 100.f, ttmlCue.line);
assertEquals(35.f / 100.f, ttmlCue.size);
output = subtitle.getCues(25000000);
ttmlCue = output.get(0);
assertEquals("She first said this\nThen this", ttmlCue.text.toString());
output = subtitle.getCues(29000000);
assertEquals(1, output.size());
ttmlCue = output.get(0);
assertEquals("She first said this\nThen this\nFinally this", ttmlCue.text.toString());
assertEquals(45.f / 100.f, ttmlCue.position);
assertEquals(45.f / 100.f, ttmlCue.line);
}
Aggregations