Java Code Examples for com.google.android.exoplayer2.extractor.SeekMap#isSeekable()

The following examples show how to use com.google.android.exoplayer2.extractor.SeekMap#isSeekable() . 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: ProgressiveMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  PreparedState preparedState = getPreparedState();
  SeekMap seekMap = preparedState.seekMap;
  boolean[] trackIsAudioVideoFlags = preparedState.trackIsAudioVideoFlags;
  // Treat all seeks into non-seekable media as being to t=0.
  positionUs = seekMap.isSeekable() ? positionUs : 0;

  notifyDiscontinuity = false;
  lastSeekPositionUs = positionUs;
  if (isPendingReset()) {
    // A reset is already pending. We only need to update its position.
    pendingResetPositionUs = positionUs;
    return positionUs;
  }

  // If we're not playing a live stream, try and seek within the buffer.
  if (dataType != C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
      && seekInsideBufferUs(trackIsAudioVideoFlags, positionUs)) {
    return positionUs;
  }

  // We can't seek inside the buffer, and so need to reset.
  pendingDeferredRetry = false;
  pendingResetPositionUs = positionUs;
  loadingFinished = false;
  if (loader.isLoading()) {
    loader.cancelLoading();
  } else {
    loader.clearFatalError();
    for (SampleQueue sampleQueue : sampleQueues) {
      sampleQueue.reset();
    }
  }
  return positionUs;
}
 
Example 2
Source File: ProgressiveMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  SeekMap seekMap = getPreparedState().seekMap;
  if (!seekMap.isSeekable()) {
    // Treat all seeks into non-seekable media as being to t=0.
    return 0;
  }
  SeekPoints seekPoints = seekMap.getSeekPoints(positionUs);
  return Util.resolveSeekPositionUs(
      positionUs, seekParameters, seekPoints.first.timeUs, seekPoints.second.timeUs);
}
 
Example 3
Source File: TestUtil.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that {@code extractor} consumes {@code sampleFile} successfully and its output equals
 * to a prerecorded output dump file with the name {@code sampleFile} + "{@value
 * #DUMP_EXTENSION}". If {@code simulateUnknownLength} is true and {@code sampleFile} + "{@value
 * #UNKNOWN_LENGTH_EXTENSION}" exists, it's preferred.
 *
 * @param extractor The {@link Extractor} to be tested.
 * @param sampleFile The path to the input sample.
 * @param fileData Content of the input file.
 * @param instrumentation To be used to load the sample file.
 * @param simulateIOErrors If true simulates IOErrors.
 * @param simulateUnknownLength If true simulates unknown input length.
 * @param simulatePartialReads If true simulates partial reads.
 * @return The {@link FakeExtractorOutput} used in the test.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from the input.
 */
public static FakeExtractorOutput assertOutput(Extractor extractor, String sampleFile,
    byte[] fileData, Instrumentation instrumentation, boolean simulateIOErrors,
    boolean simulateUnknownLength, boolean simulatePartialReads) throws IOException,
    InterruptedException {
  FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
      .setSimulateIOErrors(simulateIOErrors)
      .setSimulateUnknownLength(simulateUnknownLength)
      .setSimulatePartialReads(simulatePartialReads).build();

  Assert.assertTrue(sniffTestData(extractor, input));
  input.resetPeekPosition();
  FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true);

  if (simulateUnknownLength
      && assetExists(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION)) {
    extractorOutput.assertOutput(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION);
  } else {
    extractorOutput.assertOutput(instrumentation, sampleFile + ".0" + DUMP_EXTENSION);
  }

  SeekMap seekMap = extractorOutput.seekMap;
  if (seekMap.isSeekable()) {
    long durationUs = seekMap.getDurationUs();
    for (int j = 0; j < 4; j++) {
      long timeUs = (durationUs * j) / 3;
      long position = seekMap.getPosition(timeUs);
      input.setPosition((int) position);
      for (int i = 0; i < extractorOutput.numberOfTracks; i++) {
        extractorOutput.trackOutputs.valueAt(i).clear();
      }

      consumeTestData(extractor, input, timeUs, extractorOutput, false);
      extractorOutput.assertOutput(instrumentation, sampleFile + '.' + j + DUMP_EXTENSION);
    }
  }

  return extractorOutput;
}
 
Example 4
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  PreparedState preparedState = getPreparedState();
  SeekMap seekMap = preparedState.seekMap;
  boolean[] trackIsAudioVideoFlags = preparedState.trackIsAudioVideoFlags;
  // Treat all seeks into non-seekable media as being to t=0.
  positionUs = seekMap.isSeekable() ? positionUs : 0;

  notifyDiscontinuity = false;
  lastSeekPositionUs = positionUs;
  if (isPendingReset()) {
    // A reset is already pending. We only need to update its position.
    pendingResetPositionUs = positionUs;
    return positionUs;
  }

  // If we're not playing a live stream, try and seek within the buffer.
  if (dataType != C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
      && seekInsideBufferUs(trackIsAudioVideoFlags, positionUs)) {
    return positionUs;
  }

  // We can't seek inside the buffer, and so need to reset.
  pendingDeferredRetry = false;
  pendingResetPositionUs = positionUs;
  loadingFinished = false;
  if (loader.isLoading()) {
    loader.cancelLoading();
  } else {
    loader.clearFatalError();
    for (SampleQueue sampleQueue : sampleQueues) {
      sampleQueue.reset();
    }
  }
  return positionUs;
}
 
Example 5
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  SeekMap seekMap = getPreparedState().seekMap;
  if (!seekMap.isSeekable()) {
    // Treat all seeks into non-seekable media as being to t=0.
    return 0;
  }
  SeekPoints seekPoints = seekMap.getSeekPoints(positionUs);
  return Util.resolveSeekPositionUs(
      positionUs, seekParameters, seekPoints.first.timeUs, seekPoints.second.timeUs);
}
 
Example 6
Source File: ProgressiveMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  PreparedState preparedState = getPreparedState();
  SeekMap seekMap = preparedState.seekMap;
  boolean[] trackIsAudioVideoFlags = preparedState.trackIsAudioVideoFlags;
  // Treat all seeks into non-seekable media as being to t=0.
  positionUs = seekMap.isSeekable() ? positionUs : 0;

  notifyDiscontinuity = false;
  lastSeekPositionUs = positionUs;
  if (isPendingReset()) {
    // A reset is already pending. We only need to update its position.
    pendingResetPositionUs = positionUs;
    return positionUs;
  }

  // If we're not playing a live stream, try and seek within the buffer.
  if (dataType != C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
      && seekInsideBufferUs(trackIsAudioVideoFlags, positionUs)) {
    return positionUs;
  }

  // We can't seek inside the buffer, and so need to reset.
  pendingDeferredRetry = false;
  pendingResetPositionUs = positionUs;
  loadingFinished = false;
  if (loader.isLoading()) {
    loader.cancelLoading();
  } else {
    loader.clearFatalError();
    for (SampleQueue sampleQueue : sampleQueues) {
      sampleQueue.reset();
    }
  }
  return positionUs;
}
 
Example 7
Source File: ProgressiveMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  SeekMap seekMap = getPreparedState().seekMap;
  if (!seekMap.isSeekable()) {
    // Treat all seeks into non-seekable media as being to t=0.
    return 0;
  }
  SeekPoints seekPoints = seekMap.getSeekPoints(positionUs);
  return Util.resolveSeekPositionUs(
      positionUs, seekParameters, seekPoints.first.timeUs, seekPoints.second.timeUs);
}