本文整理汇总了Java中com.google.android.exoplayer.text.Cue类的典型用法代码示例。如果您正苦于以下问题:Java Cue类的具体用法?Java Cue怎么用?Java Cue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cue类属于com.google.android.exoplayer.text包,在下文中一共展示了Cue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
@Override
public Mp4WebvttSubtitle parse(byte[] bytes, int offset, int length) throws ParserException {
// Webvtt in Mp4 samples have boxes inside of them, so we have to do a traditional box parsing:
// first 4 bytes size and then 4 bytes type.
sampleData.reset(bytes, offset + length);
sampleData.setPosition(offset);
List<Cue> resultingCueList = new ArrayList<>();
while (sampleData.bytesLeft() > 0) {
if (sampleData.bytesLeft() < BOX_HEADER_SIZE) {
throw new ParserException("Incomplete Mp4Webvtt Top Level box header found.");
}
int boxSize = sampleData.readInt();
int boxType = sampleData.readInt();
if (boxType == TYPE_vttc) {
resultingCueList.add(parseVttCueBox(sampleData, builder, boxSize - BOX_HEADER_SIZE));
} else {
// Peers of the VTTCueBox are still not supported and are skipped.
sampleData.skipBytes(boxSize - BOX_HEADER_SIZE);
}
}
return new Mp4WebvttSubtitle(resultingCueList);
}
示例2: parseVttCueBox
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private static Cue parseVttCueBox(ParsableByteArray sampleData, WebvttCue.Builder builder,
int remainingCueBoxBytes) throws ParserException {
builder.reset();
while (remainingCueBoxBytes > 0) {
if (remainingCueBoxBytes < BOX_HEADER_SIZE) {
throw new ParserException("Incomplete vtt cue box header found.");
}
int boxSize = sampleData.readInt();
int boxType = sampleData.readInt();
remainingCueBoxBytes -= BOX_HEADER_SIZE;
int payloadLength = boxSize - BOX_HEADER_SIZE;
String boxPayload = new String(sampleData.data, sampleData.getPosition(), payloadLength);
sampleData.skipBytes(payloadLength);
remainingCueBoxBytes -= payloadLength;
if (boxType == TYPE_sttg) {
WebvttCueParser.parseCueSettingsList(boxPayload, builder);
} else if (boxType == TYPE_payl) {
WebvttCueParser.parseCueText(boxPayload.trim(), builder);
} else {
// Other VTTCueBox children are still not supported and are ignored.
}
}
return builder.build();
}
示例3: derivePositionAnchorFromAlignment
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private Builder derivePositionAnchorFromAlignment() {
if (textAlignment == null) {
positionAnchor = Cue.TYPE_UNSET;
} else {
switch (textAlignment) {
case ALIGN_NORMAL:
positionAnchor = Cue.ANCHOR_TYPE_START;
break;
case ALIGN_CENTER:
positionAnchor = Cue.ANCHOR_TYPE_MIDDLE;
break;
case ALIGN_OPPOSITE:
positionAnchor = Cue.ANCHOR_TYPE_END;
break;
default:
Log.w(TAG, "Unrecognized alignment: " + textAlignment);
positionAnchor = Cue.ANCHOR_TYPE_START;
break;
}
}
return this;
}
示例4: assertCue
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
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);
}
示例5: assertSpans
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
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);
}
示例6: parse
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
@Override
public Subtitle parse(InputStream inputStream, String inputEncoding, long startTimeUs)
throws IOException {
DataInputStream dataInputStream = new DataInputStream(inputStream);
String cueText = dataInputStream.readUTF();
return new Tx3gSubtitle(startTimeUs, new Cue(cueText));
}
示例7: invokeRendererInternal
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private void invokeRendererInternal(String cueText) {
if (cueText == null) {
textRenderer.onCues(Collections.<Cue>emptyList());
} else {
textRenderer.onCues(Collections.singletonList(new Cue(cueText)));
}
}
示例8: getCues
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
@Override
public List<Cue> getCues(long timeUs) {
CharSequence cueText = root.getText(timeUs - startTimeUs);
if (cueText == null) {
return Collections.<Cue>emptyList();
} else {
Cue cue = new Cue(cueText);
return Collections.singletonList(cue);
}
}
示例9: getCues
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
@Override
public List<Cue> getCues(long timeUs) {
int index = Util.binarySearchFloor(cueTimesUs, timeUs, true, false);
if (index == -1 || index % 2 == 1) {
// timeUs is earlier than the start of the first cue, or corresponds to a gap between cues.
return Collections.<Cue>emptyList();
} else {
return Collections.singletonList(cues[index / 2]);
}
}
示例10: selectTrack
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
public void selectTrack(int type, int index) {
if (selectedTracks[type] == index) {
return;
}
selectedTracks[type] = index;
pushTrackSelection(type, true);
if (type == TYPE_TEXT && index == DISABLED_TRACK && captionListener != null) {
captionListener.onCues(Collections.<Cue>emptyList());
}
}
示例11: parseLineAttribute
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private static void parseLineAttribute(String s, WebvttCue.Builder builder)
throws NumberFormatException {
int commaPosition = s.indexOf(',');
if (commaPosition != -1) {
builder.setLineAnchor(parsePositionAnchor(s.substring(commaPosition + 1)));
s = s.substring(0, commaPosition);
} else {
builder.setLineAnchor(Cue.TYPE_UNSET);
}
if (s.endsWith("%")) {
builder.setLine(WebvttParserUtil.parsePercentage(s)).setLineType(Cue.LINE_TYPE_FRACTION);
} else {
builder.setLine(Integer.parseInt(s)).setLineType(Cue.LINE_TYPE_NUMBER);
}
}
示例12: parsePositionAttribute
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private static void parsePositionAttribute(String s, WebvttCue.Builder builder)
throws NumberFormatException {
int commaPosition = s.indexOf(',');
if (commaPosition != -1) {
builder.setPositionAnchor(parsePositionAnchor(s.substring(commaPosition + 1)));
s = s.substring(0, commaPosition);
} else {
builder.setPositionAnchor(Cue.TYPE_UNSET);
}
builder.setPosition(WebvttParserUtil.parsePercentage(s));
}
示例13: parsePositionAnchor
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
private static int parsePositionAnchor(String s) {
switch (s) {
case "start":
return Cue.ANCHOR_TYPE_START;
case "center":
case "middle":
return Cue.ANCHOR_TYPE_MIDDLE;
case "end":
return Cue.ANCHOR_TYPE_END;
default:
Log.w(TAG, "Invalid anchor value: " + s);
return Cue.TYPE_UNSET;
}
}
示例14: reset
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
public void reset() {
startTime = 0;
endTime = 0;
text = null;
textAlignment = null;
line = Cue.DIMEN_UNSET;
lineType = Cue.TYPE_UNSET;
lineAnchor = Cue.TYPE_UNSET;
position = Cue.DIMEN_UNSET;
positionAnchor = Cue.TYPE_UNSET;
width = Cue.DIMEN_UNSET;
}
示例15: build
import com.google.android.exoplayer.text.Cue; //导入依赖的package包/类
public WebvttCue build() {
if (position != Cue.DIMEN_UNSET && positionAnchor == Cue.TYPE_UNSET) {
derivePositionAnchorFromAlignment();
}
return new WebvttCue(startTime, endTime, text, textAlignment, line, lineType, lineAnchor,
position, positionAnchor, width);
}