use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SubtitleViewUtilsTest method testRemoveEmbeddedFontSizes.
@Test
public void testRemoveEmbeddedFontSizes() {
Cue.Builder cueBuilder = CUE.buildUpon();
SubtitleViewUtils.removeEmbeddedFontSizes(cueBuilder);
Cue strippedCue = cueBuilder.build();
Spanned originalText = (Spanned) CUE.text;
Spanned strippedText = (Spanned) strippedCue.text;
// Assert all non text-size properties and spans are kept
assertThat(strippedCue.textAlignment).isEqualTo(CUE.textAlignment);
assertThat(strippedCue.multiRowAlignment).isEqualTo(CUE.multiRowAlignment);
assertThat(strippedCue.line).isEqualTo(CUE.line);
assertThat(strippedCue.lineType).isEqualTo(CUE.lineType);
assertThat(strippedCue.position).isEqualTo(CUE.position);
assertThat(strippedCue.positionAnchor).isEqualTo(CUE.positionAnchor);
assertThat(strippedCue.size).isEqualTo(CUE.size);
assertThat(strippedCue.windowColor).isEqualTo(CUE.windowColor);
assertThat(strippedCue.windowColorSet).isEqualTo(CUE.windowColorSet);
assertThat(strippedCue.verticalType).isEqualTo(CUE.verticalType);
assertThat(strippedCue.shearDegrees).isEqualTo(CUE.shearDegrees);
TextEmphasisSpan expectedTextEmphasisSpan = originalText.getSpans(0, originalText.length(), TextEmphasisSpan.class)[0];
assertThat(strippedText).hasTextEmphasisSpanBetween(originalText.getSpanStart(expectedTextEmphasisSpan), originalText.getSpanEnd(expectedTextEmphasisSpan));
RubySpan expectedRubySpan = originalText.getSpans(0, originalText.length(), RubySpan.class)[0];
assertThat(strippedText).hasRubySpanBetween(originalText.getSpanStart(expectedRubySpan), originalText.getSpanEnd(expectedRubySpan));
HorizontalTextInVerticalContextSpan expectedHorizontalTextInVerticalContextSpan = originalText.getSpans(0, originalText.length(), HorizontalTextInVerticalContextSpan.class)[0];
assertThat(strippedText).hasHorizontalTextInVerticalContextSpanBetween(originalText.getSpanStart(expectedHorizontalTextInVerticalContextSpan), originalText.getSpanEnd(expectedHorizontalTextInVerticalContextSpan));
UnderlineSpan expectedUnderlineSpan = originalText.getSpans(0, originalText.length(), UnderlineSpan.class)[0];
assertThat(strippedText).hasUnderlineSpanBetween(originalText.getSpanStart(expectedUnderlineSpan), originalText.getSpanEnd(expectedUnderlineSpan));
// Assert the text-size properties and spans are removed
assertThat(strippedCue.textSize).isEqualTo(Cue.DIMEN_UNSET);
assertThat(strippedCue.textSizeType).isEqualTo(Cue.TYPE_UNSET);
assertThat(strippedText).hasNoRelativeSizeSpanBetween(0, strippedText.length());
assertThat(strippedText).hasNoAbsoluteSizeSpanBetween(0, strippedText.length());
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class CanvasSubtitleOutput method dispatchDraw.
@Override
public void dispatchDraw(Canvas canvas) {
@Nullable List<Cue> cues = this.cues;
if (cues.isEmpty()) {
return;
}
int rawViewHeight = getHeight();
// Calculate the cue box bounds relative to the canvas after padding is taken into account.
int left = getPaddingLeft();
int top = getPaddingTop();
int right = getWidth() - getPaddingRight();
int bottom = rawViewHeight - getPaddingBottom();
if (bottom <= top || right <= left) {
// No space to draw subtitles.
return;
}
int viewHeightMinusPadding = bottom - top;
float defaultViewTextSizePx = SubtitleViewUtils.resolveTextSize(textSizeType, textSize, rawViewHeight, viewHeightMinusPadding);
if (defaultViewTextSizePx <= 0) {
// Text has no height.
return;
}
int cueCount = cues.size();
for (int i = 0; i < cueCount; i++) {
Cue cue = cues.get(i);
if (cue.verticalType != Cue.TYPE_UNSET) {
cue = repositionVerticalCue(cue);
}
float cueTextSizePx = SubtitleViewUtils.resolveTextSize(cue.textSizeType, cue.textSize, rawViewHeight, viewHeightMinusPadding);
SubtitlePainter painter = painters.get(i);
painter.draw(cue, style, defaultViewTextSizePx, cueTextSizePx, bottomPaddingFraction, canvas, left, top, right, bottom);
}
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SubripDecoderTest method assertAlignmentCue.
private static void assertAlignmentCue(Subtitle subtitle, int eventIndex, @Cue.AnchorType int lineAnchor, @Cue.AnchorType int positionAnchor) {
long eventTimeUs = subtitle.getEventTime(eventIndex);
Cue cue = subtitle.getCues(eventTimeUs).get(0);
assertThat(cue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
assertThat(cue.lineAnchor).isEqualTo(lineAnchor);
assertThat(cue.line).isEqualTo(SubripDecoder.getFractionalPositionForAnchorType(lineAnchor));
assertThat(cue.positionAnchor).isEqualTo(positionAnchor);
assertThat(cue.position).isEqualTo(SubripDecoder.getFractionalPositionForAnchorType(positionAnchor));
}
use of com.google.android.exoplayer2.text.Cue in project ExoPlayer by google.
the class SubripDecoderTest method decodeTypicalNegativeTimestamps.
@Test
public void decodeTypicalNegativeTimestamps() throws IOException {
// Parsing should succeed, parsing the third cue only.
SubripDecoder decoder = new SubripDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL_NEGATIVE_TIMESTAMPS);
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 SsaDecoderTest method decodeOverlappingTimecodes.
@Test
public void decodeOverlappingTimecodes() throws IOException {
SsaDecoder decoder = new SsaDecoder();
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), OVERLAPPING_TIMECODES);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertThat(subtitle.getEventTime(0)).isEqualTo(1_000_000);
assertThat(subtitle.getEventTime(1)).isEqualTo(2_000_000);
assertThat(subtitle.getEventTime(2)).isEqualTo(4_230_000);
assertThat(subtitle.getEventTime(3)).isEqualTo(5_230_000);
assertThat(subtitle.getEventTime(4)).isEqualTo(6_000_000);
assertThat(subtitle.getEventTime(5)).isEqualTo(8_440_000);
assertThat(subtitle.getEventTime(6)).isEqualTo(9_440_000);
assertThat(subtitle.getEventTime(7)).isEqualTo(10_720_000);
assertThat(subtitle.getEventTime(8)).isEqualTo(13_220_000);
assertThat(subtitle.getEventTime(9)).isEqualTo(14_220_000);
assertThat(subtitle.getEventTime(10)).isEqualTo(15_650_000);
String firstSubtitleText = "First subtitle - end overlaps second";
String secondSubtitleText = "Second subtitle - beginning overlaps first";
String thirdSubtitleText = "Third subtitle - out of order";
String fourthSubtitleText = "Fourth subtitle - same timings as fifth";
String fifthSubtitleText = "Fifth subtitle - same timings as fourth";
String sixthSubtitleText = "Sixth subtitle - fully encompasses seventh";
String seventhSubtitleText = "Seventh subtitle - nested fully inside sixth";
assertThat(Iterables.transform(subtitle.getCues(1_000_010), cue -> cue.text.toString())).containsExactly(firstSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(2_000_010), cue -> cue.text.toString())).containsExactly(firstSubtitleText, secondSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(4_230_010), cue -> cue.text.toString())).containsExactly(secondSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(5_230_010), cue -> cue.text.toString())).isEmpty();
assertThat(Iterables.transform(subtitle.getCues(6_000_010), cue -> cue.text.toString())).containsExactly(thirdSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(8_440_010), cue -> cue.text.toString())).containsExactly(fourthSubtitleText, fifthSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(9_440_010), cue -> cue.text.toString())).isEmpty();
assertThat(Iterables.transform(subtitle.getCues(10_720_010), cue -> cue.text.toString())).containsExactly(sixthSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(13_220_010), cue -> cue.text.toString())).containsExactly(sixthSubtitleText, seventhSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(14_220_010), cue -> cue.text.toString())).containsExactly(sixthSubtitleText);
assertThat(Iterables.transform(subtitle.getCues(15_650_010), cue -> cue.text.toString())).isEmpty();
}
Aggregations