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


Java MpegAudioHeader类代码示例

本文整理汇总了Java中com.google.android.exoplayer2.extractor.MpegAudioHeader的典型用法代码示例。如果您正苦于以下问题:Java MpegAudioHeader类的具体用法?Java MpegAudioHeader怎么用?Java MpegAudioHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: read

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (synchronizedHeaderData == 0) {
    try {
      synchronize(input, false);
    } catch (EOFException e) {
      return RESULT_END_OF_INPUT;
    }
  }
  if (seeker == null) {
    seeker = setupSeeker(input);
    extractorOutput.seekMap(seeker);
    trackOutput.format(Format.createAudioSampleFormat(null, synchronizedHeader.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, synchronizedHeader.channels,
        synchronizedHeader.sampleRate, Format.NO_VALUE, gaplessInfoHolder.encoderDelay,
        gaplessInfoHolder.encoderPadding, null, null, 0, null,
        (flags & FLAG_DISABLE_ID3_METADATA) != 0 ? null : metadata));
  }
  return readSample(input);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:22,代码来源:Mp3Extractor.java

示例2: read

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (synchronizedHeaderData == 0) {
    try {
      synchronize(input, false);
    } catch (EOFException e) {
      return RESULT_END_OF_INPUT;
    }
  }
  if (seeker == null) {
    seeker = setupSeeker(input);
    extractorOutput.seekMap(seeker);
    trackOutput.format(Format.createAudioSampleFormat(null, synchronizedHeader.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, synchronizedHeader.channels,
        synchronizedHeader.sampleRate, Format.NO_VALUE, gaplessInfoHolder.encoderDelay,
        gaplessInfoHolder.encoderPadding, null, null, 0, null));
  }
  return readSample(input);
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:21,代码来源:Mp3Extractor.java

示例3: read

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (synchronizedHeaderData == 0) {
    try {
      synchronize(input, false);
    } catch (EOFException e) {
      return RESULT_END_OF_INPUT;
    }
  }
  if (seeker == null) {
    seeker = maybeReadSeekFrame(input);
    if (seeker == null
        || (!seeker.isSeekable() && (flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0)) {
      seeker = getConstantBitrateSeeker(input);
    }
    extractorOutput.seekMap(seeker);
    trackOutput.format(Format.createAudioSampleFormat(null, synchronizedHeader.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, synchronizedHeader.channels,
        synchronizedHeader.sampleRate, Format.NO_VALUE, gaplessInfoHolder.encoderDelay,
        gaplessInfoHolder.encoderPadding, null, null, 0, null,
        (flags & FLAG_DISABLE_ID3_METADATA) != 0 ? null : metadata));
  }
  return readSample(input);
}
 
开发者ID:y20k,项目名称:transistor,代码行数:26,代码来源:Mp3Extractor.java

示例4: MpegAudioReader

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
public MpegAudioReader(String language) {
  state = STATE_FINDING_HEADER;
  // The first byte of an MPEG Audio frame header is always 0xFF.
  headerScratch = new ParsableByteArray(4);
  headerScratch.data[0] = (byte) 0xFF;
  header = new MpegAudioHeader();
  this.language = language;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:9,代码来源:MpegAudioReader.java

示例5: readHeaderRemainder

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的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

示例6: Mp3Extractor

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * Constructs a new {@link Mp3Extractor}.
 *
 * @param flags Flags that control the extractor's behavior.
 * @param forcedFirstSampleTimestampUs A timestamp to force for the first sample, or
 *     {@link C#TIME_UNSET} if forcing is not required.
 */
public Mp3Extractor(@Flags int flags, long forcedFirstSampleTimestampUs) {
  this.flags = flags;
  this.forcedFirstSampleTimestampUs = forcedFirstSampleTimestampUs;
  scratch = new ParsableByteArray(SCRATCH_LENGTH);
  synchronizedHeader = new MpegAudioHeader();
  gaplessInfoHolder = new GaplessInfoHolder();
  basisTimeUs = C.TIME_UNSET;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:16,代码来源:Mp3Extractor.java

示例7: readSample

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
private int readSample(ExtractorInput extractorInput) throws IOException, InterruptedException {
  if (sampleBytesRemaining == 0) {
    extractorInput.resetPeekPosition();
    if (!extractorInput.peekFully(scratch.data, 0, 4, true)) {
      return RESULT_END_OF_INPUT;
    }
    scratch.setPosition(0);
    int sampleHeaderData = scratch.readInt();
    if ((sampleHeaderData & HEADER_MASK) != (synchronizedHeaderData & HEADER_MASK)
        || MpegAudioHeader.getFrameSize(sampleHeaderData) == C.LENGTH_UNSET) {
      // We have lost synchronization, so attempt to resynchronize starting at the next byte.
      extractorInput.skipFully(1);
      synchronizedHeaderData = 0;
      return RESULT_CONTINUE;
    }
    MpegAudioHeader.populateHeader(sampleHeaderData, synchronizedHeader);
    if (basisTimeUs == C.TIME_UNSET) {
      basisTimeUs = seeker.getTimeUs(extractorInput.getPosition());
      if (forcedFirstSampleTimestampUs != C.TIME_UNSET) {
        long embeddedFirstSampleTimestampUs = seeker.getTimeUs(0);
        basisTimeUs += forcedFirstSampleTimestampUs - embeddedFirstSampleTimestampUs;
      }
    }
    sampleBytesRemaining = synchronizedHeader.frameSize;
  }
  int bytesAppended = trackOutput.sampleData(extractorInput, sampleBytesRemaining, true);
  if (bytesAppended == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }
  sampleBytesRemaining -= bytesAppended;
  if (sampleBytesRemaining > 0) {
    return RESULT_CONTINUE;
  }
  long timeUs = basisTimeUs + (samplesRead * C.MICROS_PER_SECOND / synchronizedHeader.sampleRate);
  trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, synchronizedHeader.frameSize, 0,
      null);
  samplesRead += synchronizedHeader.samplesPerFrame;
  sampleBytesRemaining = 0;
  return RESULT_CONTINUE;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:41,代码来源:Mp3Extractor.java

示例8: create

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * Returns a {@link XingSeeker} for seeking in the stream, if required information is present.
 * Returns {@code null} if not. On returning, {@code frame}'s position is not specified so the
 * caller should reset it.
 *
 * @param mpegAudioHeader The MPEG audio header associated with the frame.
 * @param frame The data in this audio frame, with its position set to immediately after the
 *    'Xing' or 'Info' tag.
 * @param position The position (byte offset) of the start of this frame in the stream.
 * @param inputLength The length of the stream in bytes.
 * @return A {@link XingSeeker} for seeking in the stream, or {@code null} if the required
 *     information is not present.
 */
public static XingSeeker create(MpegAudioHeader mpegAudioHeader, ParsableByteArray frame,
    long position, long inputLength) {
  int samplesPerFrame = mpegAudioHeader.samplesPerFrame;
  int sampleRate = mpegAudioHeader.sampleRate;
  long firstFramePosition = position + mpegAudioHeader.frameSize;

  int flags = frame.readInt();
  int frameCount;
  if ((flags & 0x01) != 0x01 || (frameCount = frame.readUnsignedIntToInt()) == 0) {
    // If the frame count is missing/invalid, the header can't be used to determine the duration.
    return null;
  }
  long durationUs = Util.scaleLargeTimestamp(frameCount, samplesPerFrame * C.MICROS_PER_SECOND,
      sampleRate);
  if ((flags & 0x06) != 0x06) {
    // If the size in bytes or table of contents is missing, the stream is not seekable.
    return new XingSeeker(firstFramePosition, durationUs, inputLength);
  }

  long sizeBytes = frame.readUnsignedIntToInt();
  frame.skipBytes(1);
  long[] tableOfContents = new long[99];
  for (int i = 0; i < 99; i++) {
    tableOfContents[i] = frame.readUnsignedByte();
  }

  // TODO: Handle encoder delay and padding in 3 bytes offset by xingBase + 213 bytes:
  // delay = (frame.readUnsignedByte() << 4) + (frame.readUnsignedByte() >> 4);
  // padding = ((frame.readUnsignedByte() & 0x0F) << 8) + frame.readUnsignedByte();
  return new XingSeeker(firstFramePosition, durationUs, inputLength, tableOfContents,
      sizeBytes, mpegAudioHeader.frameSize);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:46,代码来源:XingSeeker.java

示例9: readHeaderRemainder

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的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(null, 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:zhanglibin123488,项目名称:videoPickPlayer,代码行数:49,代码来源:MpegAudioReader.java

示例10: Mp3Extractor

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * Constructs a new {@link Mp3Extractor}.
 *
 * @param forcedFirstSampleTimestampUs A timestamp to force for the first sample, or
 *     {@link C#TIME_UNSET} if forcing is not required.
 */
public Mp3Extractor(long forcedFirstSampleTimestampUs) {
  this.forcedFirstSampleTimestampUs = forcedFirstSampleTimestampUs;
  scratch = new ParsableByteArray(4);
  synchronizedHeader = new MpegAudioHeader();
  gaplessInfoHolder = new GaplessInfoHolder();
  basisTimeUs = C.TIME_UNSET;
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:14,代码来源:Mp3Extractor.java

示例11: setUp

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
  MpegAudioHeader xingFrameHeader = new MpegAudioHeader();
  MpegAudioHeader.populateHeader(XING_FRAME_HEADER_DATA, xingFrameHeader);
  seeker = XingSeeker.create(xingFrameHeader, new ParsableByteArray(XING_FRAME_PAYLOAD),
      XING_FRAME_POSITION, C.LENGTH_UNSET);
  seekerWithInputLength = XingSeeker.create(xingFrameHeader,
      new ParsableByteArray(XING_FRAME_PAYLOAD), XING_FRAME_POSITION, INPUT_LENGTH);
  xingFrameSize = xingFrameHeader.frameSize;
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:11,代码来源:XingSeekerTest.java

示例12: Mp3Extractor

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * @param flags Flags that control the extractor's behavior.
 * @param forcedFirstSampleTimestampUs A timestamp to force for the first sample, or
 *     {@link C#TIME_UNSET} if forcing is not required.
 */
public Mp3Extractor(@Flags int flags, long forcedFirstSampleTimestampUs) {
  this.flags = flags;
  this.forcedFirstSampleTimestampUs = forcedFirstSampleTimestampUs;
  scratch = new ParsableByteArray(SCRATCH_LENGTH);
  synchronizedHeader = new MpegAudioHeader();
  gaplessInfoHolder = new GaplessInfoHolder();
  basisTimeUs = C.TIME_UNSET;
}
 
开发者ID:y20k,项目名称:transistor,代码行数:14,代码来源:Mp3Extractor.java

示例13: readSample

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
private int readSample(ExtractorInput extractorInput) throws IOException, InterruptedException {
  if (sampleBytesRemaining == 0) {
    extractorInput.resetPeekPosition();
    if (!extractorInput.peekFully(scratch.data, 0, 4, true)) {
      return RESULT_END_OF_INPUT;
    }
    scratch.setPosition(0);
    int sampleHeaderData = scratch.readInt();
    if (!headersMatch(sampleHeaderData, synchronizedHeaderData)
        || MpegAudioHeader.getFrameSize(sampleHeaderData) == C.LENGTH_UNSET) {
      // We have lost synchronization, so attempt to resynchronize starting at the next byte.
      extractorInput.skipFully(1);
      synchronizedHeaderData = 0;
      return RESULT_CONTINUE;
    }
    MpegAudioHeader.populateHeader(sampleHeaderData, synchronizedHeader);
    if (basisTimeUs == C.TIME_UNSET) {
      basisTimeUs = seeker.getTimeUs(extractorInput.getPosition());
      if (forcedFirstSampleTimestampUs != C.TIME_UNSET) {
        long embeddedFirstSampleTimestampUs = seeker.getTimeUs(0);
        basisTimeUs += forcedFirstSampleTimestampUs - embeddedFirstSampleTimestampUs;
      }
    }
    sampleBytesRemaining = synchronizedHeader.frameSize;
  }
  int bytesAppended = trackOutput.sampleData(extractorInput, sampleBytesRemaining, true);
  if (bytesAppended == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }
  sampleBytesRemaining -= bytesAppended;
  if (sampleBytesRemaining > 0) {
    return RESULT_CONTINUE;
  }
  long timeUs = basisTimeUs + (samplesRead * C.MICROS_PER_SECOND / synchronizedHeader.sampleRate);
  trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, synchronizedHeader.frameSize, 0,
      null);
  samplesRead += synchronizedHeader.samplesPerFrame;
  sampleBytesRemaining = 0;
  return RESULT_CONTINUE;
}
 
开发者ID:y20k,项目名称:transistor,代码行数:41,代码来源:Mp3Extractor.java

示例14: getConstantBitrateSeeker

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * Peeks the next frame and returns a {@link ConstantBitrateSeeker} based on its bitrate.
 */
private Seeker getConstantBitrateSeeker(ExtractorInput input)
    throws IOException, InterruptedException {
  input.peekFully(scratch.data, 0, 4);
  scratch.setPosition(0);
  MpegAudioHeader.populateHeader(scratch.readInt(), synchronizedHeader);
  return new ConstantBitrateSeeker(input.getLength(), input.getPosition(), synchronizedHeader);
}
 
开发者ID:y20k,项目名称:transistor,代码行数:11,代码来源:Mp3Extractor.java

示例15: ConstantBitrateSeeker

import com.google.android.exoplayer2.extractor.MpegAudioHeader; //导入依赖的package包/类
/**
 * @param inputLength The length of the stream in bytes, or {@link C#LENGTH_UNSET} if unknown.
 * @param firstFramePosition The position of the first frame in the stream.
 * @param mpegAudioHeader The MPEG audio header associated with the first frame.
 */
public ConstantBitrateSeeker(long inputLength, long firstFramePosition,
    MpegAudioHeader mpegAudioHeader) {
  this.firstFramePosition = firstFramePosition;
  this.frameSize = mpegAudioHeader.frameSize;
  this.bitrate = mpegAudioHeader.bitrate;
  if (inputLength == C.LENGTH_UNSET) {
    dataSize = C.LENGTH_UNSET;
    durationUs = C.TIME_UNSET;
  } else {
    dataSize = inputLength - firstFramePosition;
    durationUs = getTimeUs(inputLength);
  }
}
 
开发者ID:y20k,项目名称:transistor,代码行数:19,代码来源:ConstantBitrateSeeker.java


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