当前位置: 首页>>代码示例>>Java>>正文


Java ParsableByteArray.readBytes方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.util.ParsableByteArray.readBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ParsableByteArray.readBytes方法的具体用法?Java ParsableByteArray.readBytes怎么用?Java ParsableByteArray.readBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.util.ParsableByteArray的用法示例。


在下文中一共展示了ParsableByteArray.readBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeTextInformationFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static TextInformationFrame decodeTextInformationFrame(ParsableByteArray id3Data,
    int frameSize, String id) throws UnsupportedEncodingException {
  if (frameSize < 1) {
    // Frame is malformed.
    return null;
  }

  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[frameSize - 1];
  id3Data.readBytes(data, 0, frameSize - 1);

  int valueEndIndex = indexOfEos(data, 0, encoding);
  String value = new String(data, 0, valueEndIndex, charset);

  return new TextInformationFrame(id, null, value);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:19,代码来源:Id3Decoder.java

示例2: decodePrivFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static PrivFrame decodePrivFrame(ParsableByteArray id3Data, int frameSize)
    throws UnsupportedEncodingException {
  byte[] data = new byte[frameSize];
  id3Data.readBytes(data, 0, frameSize);

  int ownerEndIndex = indexOfZeroByte(data, 0);
  String owner = new String(data, 0, ownerEndIndex, "ISO-8859-1");

  byte[] privateData;
  int privateDataStartIndex = ownerEndIndex + 1;
  if (privateDataStartIndex < data.length) {
    privateData = Arrays.copyOfRange(data, privateDataStartIndex, data.length);
  } else {
    privateData = new byte[0];
  }

  return new PrivFrame(owner, privateData);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:19,代码来源:Id3Decoder.java

示例3: decodeGeobFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static GeobFrame decodeGeobFrame(ParsableByteArray id3Data, int frameSize)
    throws UnsupportedEncodingException {
  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[frameSize - 1];
  id3Data.readBytes(data, 0, frameSize - 1);

  int mimeTypeEndIndex = indexOfZeroByte(data, 0);
  String mimeType = new String(data, 0, mimeTypeEndIndex, "ISO-8859-1");

  int filenameStartIndex = mimeTypeEndIndex + 1;
  int filenameEndIndex = indexOfEos(data, filenameStartIndex, encoding);
  String filename = new String(data, filenameStartIndex, filenameEndIndex - filenameStartIndex,
      charset);

  int descriptionStartIndex = filenameEndIndex + delimiterLength(encoding);
  int descriptionEndIndex = indexOfEos(data, descriptionStartIndex, encoding);
  String description = new String(data, descriptionStartIndex,
      descriptionEndIndex - descriptionStartIndex, charset);

  int objectDataStartIndex = descriptionEndIndex + delimiterLength(encoding);
  byte[] objectData = Arrays.copyOfRange(data, objectDataStartIndex, data.length);

  return new GeobFrame(mimeType, filename, description, objectData);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:Id3Decoder.java

示例4: decodeTxxxFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static TextInformationFrame decodeTxxxFrame(ParsableByteArray id3Data, int frameSize)
    throws UnsupportedEncodingException {
  if (frameSize < 1) {
    // Frame is malformed.
    return null;
  }

  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[frameSize - 1];
  id3Data.readBytes(data, 0, frameSize - 1);

  int descriptionEndIndex = indexOfEos(data, 0, encoding);
  String description = new String(data, 0, descriptionEndIndex, charset);

  String value;
  int valueStartIndex = descriptionEndIndex + delimiterLength(encoding);
  if (valueStartIndex < data.length) {
    int valueEndIndex = indexOfEos(data, valueStartIndex, encoding);
    value = new String(data, valueStartIndex, valueEndIndex - valueStartIndex, charset);
  } else {
    value = "";
  }

  return new TextInformationFrame("TXXX", description, value);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:28,代码来源:Id3Decoder.java

示例5: decodeWxxxFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)
    throws UnsupportedEncodingException {
  if (frameSize < 1) {
    // Frame is malformed.
    return null;
  }

  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[frameSize - 1];
  id3Data.readBytes(data, 0, frameSize - 1);

  int descriptionEndIndex = indexOfEos(data, 0, encoding);
  String description = new String(data, 0, descriptionEndIndex, charset);

  String url;
  int urlStartIndex = descriptionEndIndex + delimiterLength(encoding);
  if (urlStartIndex < data.length) {
    int urlEndIndex = indexOfZeroByte(data, urlStartIndex);
    url = new String(data, urlStartIndex, urlEndIndex - urlStartIndex, "ISO-8859-1");
  } else {
    url = "";
  }

  return new UrlLinkFrame("WXXX", description, url);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:28,代码来源:Id3Decoder.java

示例6: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Consumes the payload of a PS packet.
 *
 * @param data The PES packet. The position will be set to the start of the payload.
 */
public void consume(ParsableByteArray data) {
  data.readBytes(pesScratch.data, 0, 3);
  pesScratch.setPosition(0);
  parseHeader();
  data.readBytes(pesScratch.data, 0, extendedHeaderLength);
  pesScratch.setPosition(0);
  parseHeaderExtension();
  pesPayloadReader.packetStarted(timeUs, true);
  pesPayloadReader.consume(data);
  // We always have complete PES packets with program stream.
  pesPayloadReader.packetFinished();
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:PsExtractor.java

示例7: continueRead

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Continues a read from the provided {@code source} into a given {@code target}. It's assumed
 * that the data should be written into {@code target} starting from an offset of zero.
 *
 * @param source The source from which to read.
 * @param target The target into which data is to be read, or {@code null} to skip.
 * @param targetLength The target length of the read.
 * @return Whether the target length has been reached.
 */
private boolean continueRead(ParsableByteArray source, byte[] target, int targetLength) {
  int bytesToRead = Math.min(source.bytesLeft(), targetLength - bytesRead);
  if (bytesToRead <= 0) {
    return true;
  } else if (target == null) {
    source.skipBytes(bytesToRead);
  } else {
    source.readBytes(target, bytesRead, bytesToRead);
  }
  bytesRead += bytesToRead;
  return bytesRead == targetLength;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:22,代码来源:PesReader.java

示例8: decodeApicFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static ApicFrame decodeApicFrame(ParsableByteArray id3Data, int frameSize,
    int majorVersion) throws UnsupportedEncodingException {
  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[frameSize - 1];
  id3Data.readBytes(data, 0, frameSize - 1);

  String mimeType;
  int mimeTypeEndIndex;
  if (majorVersion == 2) {
    mimeTypeEndIndex = 2;
    mimeType = "image/" + Util.toLowerInvariant(new String(data, 0, 3, "ISO-8859-1"));
    if (mimeType.equals("image/jpg")) {
      mimeType = "image/jpeg";
    }
  } else {
    mimeTypeEndIndex = indexOfZeroByte(data, 0);
    mimeType = Util.toLowerInvariant(new String(data, 0, mimeTypeEndIndex, "ISO-8859-1"));
    if (mimeType.indexOf('/') == -1) {
      mimeType = "image/" + mimeType;
    }
  }

  int pictureType = data[mimeTypeEndIndex + 1] & 0xFF;

  int descriptionStartIndex = mimeTypeEndIndex + 2;
  int descriptionEndIndex = indexOfEos(data, descriptionStartIndex, encoding);
  String description = new String(data, descriptionStartIndex,
      descriptionEndIndex - descriptionStartIndex, charset);

  int pictureDataStartIndex = descriptionEndIndex + delimiterLength(encoding);
  byte[] pictureData = Arrays.copyOfRange(data, pictureDataStartIndex, data.length);

  return new ApicFrame(mimeType, description, pictureType, pictureData);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:37,代码来源:Id3Decoder.java

示例9: readHeaderRemainder

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Attempts to read the remaining two bytes of the frame header.
 * <p>
 * If a frame header is read in full then the state is changed to {@link #STATE_READING_FRAME},
 * the media format is output if this has not previously occurred, the four header bytes are
 * output as sample data, and the position of the source is advanced to the byte that immediately
 * follows the header.
 * <p>
 * If a frame header is read in full but cannot be parsed then the state is changed to
 * {@link #STATE_READING_HEADER}.
 * <p>
 * If a frame header is not read in full then the position of the source is advanced to the limit,
 * and the method should be called again with the next source to continue the read.
 *
 * @param source The source from which to read.
 */
private void readHeaderRemainder(ParsableByteArray source) {
  int bytesToRead = Math.min(source.bytesLeft(), HEADER_SIZE - frameBytesRead);
  source.readBytes(headerScratch.data, frameBytesRead, bytesToRead);
  frameBytesRead += bytesToRead;
  if (frameBytesRead < HEADER_SIZE) {
    // We haven't read the whole header yet.
    return;
  }

  headerScratch.setPosition(0);
  boolean parsedHeader = MpegAudioHeader.populateHeader(headerScratch.readInt(), header);
  if (!parsedHeader) {
    // We thought we'd located a frame header, but we hadn't.
    frameBytesRead = 0;
    state = STATE_READING_HEADER;
    return;
  }

  frameSize = header.frameSize;
  if (!hasOutputFormat) {
    frameDurationUs = (C.MICROS_PER_SECOND * header.samplesPerFrame) / header.sampleRate;
    Format format = Format.createAudioSampleFormat(formatId, header.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, header.channels, header.sampleRate,
        null, null, 0, language);
    output.format(format);
    hasOutputFormat = true;
  }

  headerScratch.setPosition(0);
  output.sampleData(headerScratch, HEADER_SIZE);
  state = STATE_READING_FRAME;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:49,代码来源:MpegAudioReader.java

示例10: decodeBinaryFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static BinaryFrame decodeBinaryFrame(ParsableByteArray id3Data, int frameSize,
    String id) {
  byte[] frame = new byte[frameSize];
  id3Data.readBytes(frame, 0, frameSize);

  return new BinaryFrame(id, frame);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:8,代码来源:Id3Decoder.java

示例11: decodeCommentFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static CommentFrame decodeCommentFrame(ParsableByteArray id3Data, int frameSize)
    throws UnsupportedEncodingException {
  if (frameSize < 4) {
    // Frame is malformed.
    return null;
  }

  int encoding = id3Data.readUnsignedByte();
  String charset = getCharsetName(encoding);

  byte[] data = new byte[3];
  id3Data.readBytes(data, 0, 3);
  String language = new String(data, 0, 3);

  data = new byte[frameSize - 4];
  id3Data.readBytes(data, 0, frameSize - 4);

  int descriptionEndIndex = indexOfEos(data, 0, encoding);
  String description = new String(data, 0, descriptionEndIndex, charset);

  String text;
  int textStartIndex = descriptionEndIndex + delimiterLength(encoding);
  if (textStartIndex < data.length) {
    int textEndIndex = indexOfEos(data, textStartIndex, encoding);
    text = new String(data, textStartIndex, textEndIndex - textStartIndex, charset);
  } else {
    text = "";
  }

  return new CommentFrame(language, description, text);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:32,代码来源:Id3Decoder.java

示例12: parseTextSampleEntry

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static void parseTextSampleEntry(ParsableByteArray parent, int atomType, int position,
    int atomSize, int trackId, String language, DrmInitData drmInitData, StsdData out)
    throws ParserException {
  parent.setPosition(position + Atom.HEADER_SIZE + StsdData.STSD_HEADER_SIZE);

  // Default values.
  List<byte[]> initializationData = null;
  long subsampleOffsetUs = Format.OFFSET_SAMPLE_RELATIVE;

  String mimeType;
  if (atomType == Atom.TYPE_TTML) {
    mimeType = MimeTypes.APPLICATION_TTML;
  } else if (atomType == Atom.TYPE_tx3g) {
    mimeType = MimeTypes.APPLICATION_TX3G;
    int sampleDescriptionLength = atomSize - Atom.HEADER_SIZE - 8;
    byte[] sampleDescriptionData = new byte[sampleDescriptionLength];
    parent.readBytes(sampleDescriptionData, 0, sampleDescriptionLength);
    initializationData = Collections.singletonList(sampleDescriptionData);
  } else if (atomType == Atom.TYPE_wvtt) {
    mimeType = MimeTypes.APPLICATION_MP4VTT;
  } else if (atomType == Atom.TYPE_stpp) {
    mimeType = MimeTypes.APPLICATION_TTML;
    subsampleOffsetUs = 0; // Subsample timing is absolute.
  } else if (atomType == Atom.TYPE_c608) {
    // Defined by the QuickTime File Format specification.
    mimeType = MimeTypes.APPLICATION_MP4CEA608;
    out.requiredSampleTransformation = Track.TRANSFORMATION_CEA608_CDAT;
  } else {
    // Never happens.
    throw new IllegalStateException();
  }

  out.format = Format.createTextSampleFormat(Integer.toString(trackId), mimeType, null,
      Format.NO_VALUE, 0, language, Format.NO_VALUE, drmInitData, subsampleOffsetUs,
      initializationData);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:37,代码来源:AtomParsers.java

示例13: decodeUrlLinkFrame

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static UrlLinkFrame decodeUrlLinkFrame(ParsableByteArray id3Data, int frameSize,
    String id) throws UnsupportedEncodingException {
  byte[] data = new byte[frameSize];
  id3Data.readBytes(data, 0, frameSize);

  int urlEndIndex = indexOfZeroByte(data, 0);
  String url = new String(data, 0, urlEndIndex, "ISO-8859-1");

  return new UrlLinkFrame(id, null, url);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:11,代码来源:Id3Decoder.java

示例14: parseUuid

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
private static void parseUuid(ParsableByteArray uuid, TrackFragment out,
    byte[] extendedTypeScratch) throws ParserException {
  uuid.setPosition(Atom.HEADER_SIZE);
  uuid.readBytes(extendedTypeScratch, 0, 16);

  // Currently this parser only supports Microsoft's PIFF SampleEncryptionBox.
  if (!Arrays.equals(extendedTypeScratch, PIFF_SAMPLE_ENCRYPTION_BOX_EXTENDED_TYPE)) {
    return;
  }

  // Except for the extended type, this box is identical to a SENC box. See "Portable encoding of
  // audio-video objects: The Protected Interoperable File Format (PIFF), John A. Bocharov et al,
  // Section 5.3.2.1."
  parseSenc(uuid, 16, out);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:16,代码来源:FragmentedMp4Extractor.java

示例15: consume

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
@Override
public void consume(ParsableByteArray data, boolean payloadUnitStartIndicator) {
  int payloadStartPosition = C.POSITION_UNSET;
  if (payloadUnitStartIndicator) {
    int payloadStartOffset = data.readUnsignedByte();
    payloadStartPosition = data.getPosition() + payloadStartOffset;
  }

  if (waitingForPayloadStart) {
    if (!payloadUnitStartIndicator) {
      return;
    }
    waitingForPayloadStart = false;
    data.setPosition(payloadStartPosition);
    bytesRead = 0;
  }

  while (data.bytesLeft() > 0) {
    if (bytesRead < SECTION_HEADER_LENGTH) {
      // Note: see ISO/IEC 13818-1, section 2.4.4.3 for detailed information on the format of
      // the header.
      if (bytesRead == 0) {
        int tableId = data.readUnsignedByte();
        data.setPosition(data.getPosition() - 1);
        if (tableId == 0xFF /* forbidden value */) {
          // No more sections in this ts packet.
          waitingForPayloadStart = true;
          return;
        }
      }
      int headerBytesToRead = Math.min(data.bytesLeft(), SECTION_HEADER_LENGTH - bytesRead);
      data.readBytes(sectionData.data, bytesRead, headerBytesToRead);
      bytesRead += headerBytesToRead;
      if (bytesRead == SECTION_HEADER_LENGTH) {
        sectionData.reset(SECTION_HEADER_LENGTH);
        sectionData.skipBytes(1); // Skip table id (8).
        int secondHeaderByte = sectionData.readUnsignedByte();
        int thirdHeaderByte = sectionData.readUnsignedByte();
        sectionSyntaxIndicator = (secondHeaderByte & 0x80) != 0;
        totalSectionLength =
            (((secondHeaderByte & 0x0F) << 8) | thirdHeaderByte) + SECTION_HEADER_LENGTH;
        if (sectionData.capacity() < totalSectionLength) {
          // Ensure there is enough space to keep the whole section.
          byte[] bytes = sectionData.data;
          sectionData.reset(
              Math.min(MAX_SECTION_LENGTH, Math.max(totalSectionLength, bytes.length * 2)));
          System.arraycopy(bytes, 0, sectionData.data, 0, SECTION_HEADER_LENGTH);
        }
      }
    } else {
      // Reading the body.
      int bodyBytesToRead = Math.min(data.bytesLeft(), totalSectionLength - bytesRead);
      data.readBytes(sectionData.data, bytesRead, bodyBytesToRead);
      bytesRead += bodyBytesToRead;
      if (bytesRead == totalSectionLength) {
        if (sectionSyntaxIndicator) {
          // This section has common syntax as defined in ISO/IEC 13818-1, section 2.4.4.11.
          if (Util.crc(sectionData.data, 0, totalSectionLength, 0xFFFFFFFF) != 0) {
            // The CRC is invalid so discard the section.
            waitingForPayloadStart = true;
            return;
          }
          sectionData.reset(totalSectionLength - 4); // Exclude the CRC_32 field.
        } else {
          // This is a private section with private defined syntax.
          sectionData.reset(totalSectionLength);
        }
        reader.consume(sectionData);
        bytesRead = 0;
      }
    }
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:74,代码来源:SectionReader.java


注:本文中的com.google.android.exoplayer2.util.ParsableByteArray.readBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。