Java Code Examples for com.google.android.exoplayer2.text.Cue#TYPE_UNSET

The following examples show how to use com.google.android.exoplayer2.text.Cue#TYPE_UNSET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubripDecoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
static float getFractionalPositionForAnchorType(@Cue.AnchorType int anchorType) {
  switch (anchorType) {
    case Cue.ANCHOR_TYPE_START:
      return SubripDecoder.START_FRACTION;
    case Cue.ANCHOR_TYPE_MIDDLE:
      return SubripDecoder.MID_FRACTION;
    case Cue.ANCHOR_TYPE_END:
      return SubripDecoder.END_FRACTION;
    case Cue.TYPE_UNSET:
    default:
      // Should never happen.
      throw new IllegalArgumentException();
  }
}
 
Example 2
Source File: WebvttCueParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
  }
}
 
Example 3
Source File: Tx3gDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Subtitle decode(byte[] bytes, int length, boolean reset)
    throws SubtitleDecoderException {
  parsableByteArray.reset(bytes, length);
  String cueTextString = readSubtitleText(parsableByteArray);
  if (cueTextString.isEmpty()) {
    return Tx3gSubtitle.EMPTY;
  }
  // Attach default styles.
  SpannableStringBuilder cueText = new SpannableStringBuilder(cueTextString);
  attachFontFace(cueText, defaultFontFace, DEFAULT_FONT_FACE, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachColor(cueText, defaultColorRgba, DEFAULT_COLOR, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachFontFamily(cueText, defaultFontFamily, DEFAULT_FONT_FAMILY, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  float verticalPlacement = defaultVerticalPlacement;
  // Find and attach additional styles.
  while (parsableByteArray.bytesLeft() >= SIZE_ATOM_HEADER) {
    int position = parsableByteArray.getPosition();
    int atomSize = parsableByteArray.readInt();
    int atomType = parsableByteArray.readInt();
    if (atomType == TYPE_STYL) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int styleRecordCount = parsableByteArray.readUnsignedShort();
      for (int i = 0; i < styleRecordCount; i++) {
        applyStyleRecord(parsableByteArray, cueText);
      }
    } else if (atomType == TYPE_TBOX && customVerticalPlacement) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int requestedVerticalPlacement = parsableByteArray.readUnsignedShort();
      verticalPlacement = (float) requestedVerticalPlacement / calculatedVideoTrackHeight;
      verticalPlacement = Util.constrainValue(verticalPlacement, 0.0f, 0.95f);
    }
    parsableByteArray.setPosition(position + atomSize);
  }
  return new Tx3gSubtitle(new Cue(cueText, null, verticalPlacement, Cue.LINE_TYPE_FRACTION,
      Cue.ANCHOR_TYPE_START, Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.DIMEN_UNSET));
}
 
Example 4
Source File: SubripDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
static float getFractionalPositionForAnchorType(@Cue.AnchorType int anchorType) {
  switch (anchorType) {
    case Cue.ANCHOR_TYPE_START:
      return SubripDecoder.START_FRACTION;
    case Cue.ANCHOR_TYPE_MIDDLE:
      return SubripDecoder.MID_FRACTION;
    case Cue.ANCHOR_TYPE_END:
      return SubripDecoder.END_FRACTION;
    case Cue.TYPE_UNSET:
    default:
      // Should never happen.
      throw new IllegalArgumentException();
  }
}
 
Example 5
Source File: WebvttCueParser.java    From no-player with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 6
Source File: TtmlRegion.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public TtmlRegion(String id) {
  this(
      id,
      /* position= */ Cue.DIMEN_UNSET,
      /* line= */ Cue.DIMEN_UNSET,
      /* lineType= */ Cue.TYPE_UNSET,
      /* lineAnchor= */ Cue.TYPE_UNSET,
      /* width= */ Cue.DIMEN_UNSET,
      /* height= */ Cue.DIMEN_UNSET,
      /* textSizeType= */ Cue.TYPE_UNSET,
      /* textSize= */ Cue.DIMEN_UNSET);
}
 
Example 7
Source File: WebvttCue.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: Tx3gDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Subtitle decode(byte[] bytes, int length, boolean reset)
    throws SubtitleDecoderException {
  parsableByteArray.reset(bytes, length);
  String cueTextString = readSubtitleText(parsableByteArray);
  if (cueTextString.isEmpty()) {
    return Tx3gSubtitle.EMPTY;
  }
  // Attach default styles.
  SpannableStringBuilder cueText = new SpannableStringBuilder(cueTextString);
  attachFontFace(cueText, defaultFontFace, DEFAULT_FONT_FACE, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachColor(cueText, defaultColorRgba, DEFAULT_COLOR, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachFontFamily(cueText, defaultFontFamily, DEFAULT_FONT_FAMILY, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  float verticalPlacement = defaultVerticalPlacement;
  // Find and attach additional styles.
  while (parsableByteArray.bytesLeft() >= SIZE_ATOM_HEADER) {
    int position = parsableByteArray.getPosition();
    int atomSize = parsableByteArray.readInt();
    int atomType = parsableByteArray.readInt();
    if (atomType == TYPE_STYL) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int styleRecordCount = parsableByteArray.readUnsignedShort();
      for (int i = 0; i < styleRecordCount; i++) {
        applyStyleRecord(parsableByteArray, cueText);
      }
    } else if (atomType == TYPE_TBOX && customVerticalPlacement) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int requestedVerticalPlacement = parsableByteArray.readUnsignedShort();
      verticalPlacement = (float) requestedVerticalPlacement / calculatedVideoTrackHeight;
      verticalPlacement = Util.constrainValue(verticalPlacement, 0.0f, 0.95f);
    }
    parsableByteArray.setPosition(position + atomSize);
  }
  return new Tx3gSubtitle(new Cue(cueText, null, verticalPlacement, Cue.LINE_TYPE_FRACTION,
      Cue.ANCHOR_TYPE_START, Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.DIMEN_UNSET));
}
 
Example 9
Source File: TtmlRegion.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public TtmlRegion(String id) {
  this(
      id,
      /* position= */ Cue.DIMEN_UNSET,
      /* line= */ Cue.DIMEN_UNSET,
      /* lineType= */ Cue.TYPE_UNSET,
      /* lineAnchor= */ Cue.TYPE_UNSET,
      /* width= */ Cue.DIMEN_UNSET,
      /* height= */ Cue.DIMEN_UNSET,
      /* textSizeType= */ Cue.TYPE_UNSET,
      /* textSize= */ Cue.DIMEN_UNSET);
}
 
Example 10
Source File: SsaDecoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static float computeDefaultLineOrPosition(@Cue.AnchorType int anchor) {
  switch (anchor) {
    case Cue.ANCHOR_TYPE_START:
      return DEFAULT_MARGIN;
    case Cue.ANCHOR_TYPE_MIDDLE:
      return 0.5f;
    case Cue.ANCHOR_TYPE_END:
      return 1.0f - DEFAULT_MARGIN;
    case Cue.TYPE_UNSET:
    default:
      return Cue.DIMEN_UNSET;
  }
}
 
Example 11
Source File: WebvttCue.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: WebvttCue.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: WebvttCue.java    From K-Sonic with MIT License 5 votes vote down vote up
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);
}
 
Example 14
Source File: WebvttCue.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: Tx3gDecoder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
protected Subtitle decode(byte[] bytes, int length, boolean reset)
    throws SubtitleDecoderException {
  parsableByteArray.reset(bytes, length);
  String cueTextString = readSubtitleText(parsableByteArray);
  if (cueTextString.isEmpty()) {
    return Tx3gSubtitle.EMPTY;
  }
  // Attach default styles.
  SpannableStringBuilder cueText = new SpannableStringBuilder(cueTextString);
  attachFontFace(cueText, defaultFontFace, DEFAULT_FONT_FACE, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachColor(cueText, defaultColorRgba, DEFAULT_COLOR, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachFontFamily(cueText, defaultFontFamily, DEFAULT_FONT_FAMILY, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  float verticalPlacement = defaultVerticalPlacement;
  // Find and attach additional styles.
  while (parsableByteArray.bytesLeft() >= SIZE_ATOM_HEADER) {
    int position = parsableByteArray.getPosition();
    int atomSize = parsableByteArray.readInt();
    int atomType = parsableByteArray.readInt();
    if (atomType == TYPE_STYL) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int styleRecordCount = parsableByteArray.readUnsignedShort();
      for (int i = 0; i < styleRecordCount; i++) {
        applyStyleRecord(parsableByteArray, cueText);
      }
    } else if (atomType == TYPE_TBOX && customVerticalPlacement) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int requestedVerticalPlacement = parsableByteArray.readUnsignedShort();
      verticalPlacement = (float) requestedVerticalPlacement / calculatedVideoTrackHeight;
      verticalPlacement = Util.constrainValue(verticalPlacement, 0.0f, 0.95f);
    }
    parsableByteArray.setPosition(position + atomSize);
  }
  return new Tx3gSubtitle(
      new Cue(
          cueText,
          /* textAlignment= */ null,
          verticalPlacement,
          Cue.LINE_TYPE_FRACTION,
          Cue.ANCHOR_TYPE_START,
          Cue.DIMEN_UNSET,
          Cue.TYPE_UNSET,
          Cue.DIMEN_UNSET));
}
 
Example 16
Source File: Cea608Decoder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public Cue build(@Cue.AnchorType int forcedPositionAnchor) {
  SpannableStringBuilder cueString = new SpannableStringBuilder();
  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildCurrentLine());

  if (cueString.length() == 0) {
    // The cue is empty.
    return null;
  }

  int positionAnchor;
  // The number of empty columns before the start of the text, in the range [0-31].
  int startPadding = indent + tabOffset;
  // The number of empty columns after the end of the text, in the same range.
  int endPadding = SCREEN_CHARWIDTH - startPadding - cueString.length();
  int startEndPaddingDelta = startPadding - endPadding;
  if (forcedPositionAnchor != Cue.TYPE_UNSET) {
    positionAnchor = forcedPositionAnchor;
  } else if (captionMode == CC_MODE_POP_ON
      && (Math.abs(startEndPaddingDelta) < 3 || endPadding < 0)) {
    // Treat approximately centered pop-on captions as middle aligned. We also treat captions
    // that are wider than they should be in this way. See
    // https://github.com/google/ExoPlayer/issues/3534.
    positionAnchor = Cue.ANCHOR_TYPE_MIDDLE;
  } else if (captionMode == CC_MODE_POP_ON && startEndPaddingDelta > 0) {
    // Treat pop-on captions with less padding at the end than the start as end aligned.
    positionAnchor = Cue.ANCHOR_TYPE_END;
  } else {
    // For all other cases assume start aligned.
    positionAnchor = Cue.ANCHOR_TYPE_START;
  }

  float position;
  switch (positionAnchor) {
    case Cue.ANCHOR_TYPE_MIDDLE:
      position = 0.5f;
      break;
    case Cue.ANCHOR_TYPE_END:
      position = (float) (SCREEN_CHARWIDTH - endPadding) / SCREEN_CHARWIDTH;
      // Adjust the position to fit within the safe area.
      position = position * 0.8f + 0.1f;
      break;
    case Cue.ANCHOR_TYPE_START:
    default:
      position = (float) startPadding / SCREEN_CHARWIDTH;
      // Adjust the position to fit within the safe area.
      position = position * 0.8f + 0.1f;
      break;
  }

  int lineAnchor;
  int line;
  // Note: Row indices are in the range [1-15].
  if (captionMode == CC_MODE_ROLL_UP || row > (BASE_ROW / 2)) {
    lineAnchor = Cue.ANCHOR_TYPE_END;
    line = row - BASE_ROW;
    // Two line adjustments. The first is because line indices from the bottom of the window
    // start from -1 rather than 0. The second is a blank row to act as the safe area.
    line -= 2;
  } else {
    lineAnchor = Cue.ANCHOR_TYPE_START;
    // Line indices from the top of the window start from 0, but we want a blank row to act as
    // the safe area. As a result no adjustment is necessary.
    line = row;
  }

  return new Cue(
      cueString,
      Alignment.ALIGN_NORMAL,
      line,
      Cue.LINE_TYPE_NUMBER,
      lineAnchor,
      position,
      positionAnchor,
      Cue.DIMEN_UNSET);
}
 
Example 17
Source File: WebvttCue.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public WebvttCue(long startTime, long endTime, CharSequence text) {
  this(startTime, endTime, text, null, Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.TYPE_UNSET,
      Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.DIMEN_UNSET);
}
 
Example 18
Source File: Tx3gDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Subtitle decode(byte[] bytes, int length, boolean reset)
    throws SubtitleDecoderException {
  parsableByteArray.reset(bytes, length);
  String cueTextString = readSubtitleText(parsableByteArray);
  if (cueTextString.isEmpty()) {
    return Tx3gSubtitle.EMPTY;
  }
  // Attach default styles.
  SpannableStringBuilder cueText = new SpannableStringBuilder(cueTextString);
  attachFontFace(cueText, defaultFontFace, DEFAULT_FONT_FACE, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachColor(cueText, defaultColorRgba, DEFAULT_COLOR, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  attachFontFamily(cueText, defaultFontFamily, DEFAULT_FONT_FAMILY, 0, cueText.length(),
      SPAN_PRIORITY_LOW);
  float verticalPlacement = defaultVerticalPlacement;
  // Find and attach additional styles.
  while (parsableByteArray.bytesLeft() >= SIZE_ATOM_HEADER) {
    int position = parsableByteArray.getPosition();
    int atomSize = parsableByteArray.readInt();
    int atomType = parsableByteArray.readInt();
    if (atomType == TYPE_STYL) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int styleRecordCount = parsableByteArray.readUnsignedShort();
      for (int i = 0; i < styleRecordCount; i++) {
        applyStyleRecord(parsableByteArray, cueText);
      }
    } else if (atomType == TYPE_TBOX && customVerticalPlacement) {
      assertTrue(parsableByteArray.bytesLeft() >= SIZE_SHORT);
      int requestedVerticalPlacement = parsableByteArray.readUnsignedShort();
      verticalPlacement = (float) requestedVerticalPlacement / calculatedVideoTrackHeight;
      verticalPlacement = Util.constrainValue(verticalPlacement, 0.0f, 0.95f);
    }
    parsableByteArray.setPosition(position + atomSize);
  }
  return new Tx3gSubtitle(
      new Cue(
          cueText,
          /* textAlignment= */ null,
          verticalPlacement,
          Cue.LINE_TYPE_FRACTION,
          Cue.ANCHOR_TYPE_START,
          Cue.DIMEN_UNSET,
          Cue.TYPE_UNSET,
          Cue.DIMEN_UNSET));
}
 
Example 19
Source File: Cea608Decoder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public Cue build(@Cue.AnchorType int forcedPositionAnchor) {
  SpannableStringBuilder cueString = new SpannableStringBuilder();
  // Add any rolled up captions, separated by new lines.
  for (int i = 0; i < rolledUpCaptions.size(); i++) {
    cueString.append(rolledUpCaptions.get(i));
    cueString.append('\n');
  }
  // Add the current line.
  cueString.append(buildCurrentLine());

  if (cueString.length() == 0) {
    // The cue is empty.
    return null;
  }

  int positionAnchor;
  // The number of empty columns before the start of the text, in the range [0-31].
  int startPadding = indent + tabOffset;
  // The number of empty columns after the end of the text, in the same range.
  int endPadding = SCREEN_CHARWIDTH - startPadding - cueString.length();
  int startEndPaddingDelta = startPadding - endPadding;
  if (forcedPositionAnchor != Cue.TYPE_UNSET) {
    positionAnchor = forcedPositionAnchor;
  } else if (captionMode == CC_MODE_POP_ON
      && (Math.abs(startEndPaddingDelta) < 3 || endPadding < 0)) {
    // Treat approximately centered pop-on captions as middle aligned. We also treat captions
    // that are wider than they should be in this way. See
    // https://github.com/google/ExoPlayer/issues/3534.
    positionAnchor = Cue.ANCHOR_TYPE_MIDDLE;
  } else if (captionMode == CC_MODE_POP_ON && startEndPaddingDelta > 0) {
    // Treat pop-on captions with less padding at the end than the start as end aligned.
    positionAnchor = Cue.ANCHOR_TYPE_END;
  } else {
    // For all other cases assume start aligned.
    positionAnchor = Cue.ANCHOR_TYPE_START;
  }

  float position;
  switch (positionAnchor) {
    case Cue.ANCHOR_TYPE_MIDDLE:
      position = 0.5f;
      break;
    case Cue.ANCHOR_TYPE_END:
      position = (float) (SCREEN_CHARWIDTH - endPadding) / SCREEN_CHARWIDTH;
      // Adjust the position to fit within the safe area.
      position = position * 0.8f + 0.1f;
      break;
    case Cue.ANCHOR_TYPE_START:
    default:
      position = (float) startPadding / SCREEN_CHARWIDTH;
      // Adjust the position to fit within the safe area.
      position = position * 0.8f + 0.1f;
      break;
  }

  int lineAnchor;
  int line;
  // Note: Row indices are in the range [1-15].
  if (captionMode == CC_MODE_ROLL_UP || row > (BASE_ROW / 2)) {
    lineAnchor = Cue.ANCHOR_TYPE_END;
    line = row - BASE_ROW;
    // Two line adjustments. The first is because line indices from the bottom of the window
    // start from -1 rather than 0. The second is a blank row to act as the safe area.
    line -= 2;
  } else {
    lineAnchor = Cue.ANCHOR_TYPE_START;
    // Line indices from the top of the window start from 0, but we want a blank row to act as
    // the safe area. As a result no adjustment is necessary.
    line = row;
  }

  return new Cue(
      cueString,
      Alignment.ALIGN_NORMAL,
      line,
      Cue.LINE_TYPE_NUMBER,
      lineAnchor,
      position,
      positionAnchor,
      Cue.DIMEN_UNSET);
}
 
Example 20
Source File: WebvttCue.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public WebvttCue(long startTime, long endTime, CharSequence text) {
  this(startTime, endTime, text, null, Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.TYPE_UNSET,
      Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.DIMEN_UNSET);
}