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


Java C.LENGTH_UNSET属性代码示例

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


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

示例1: open

@Override
public long open(DataSpec dataSpec) throws FileDataSourceException {
  try {
    uri = dataSpec.uri;
    file = new RandomAccessFile(dataSpec.uri.getPath(), "r");
    file.seek(dataSpec.position);
    bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
        : dataSpec.length;
    if (bytesRemaining < 0) {
      throw new EOFException();
    }
  } catch (IOException e) {
    throw new FileDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart(this, dataSpec);
  }

  return bytesRemaining;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:22,代码来源:FileDataSource.java

示例2: open

@Override
public long open(DataSpec dataSpec) throws FileDataSourceException {
    try {
        uri = dataSpec.uri;
        file = new RandomAccessFile(dataSpec.uri.getPath(), "r");
        boolean ass = isEncrypted(file);
        if (ass) {
            file.seek(dataSpec.position + length);
        }
        bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
                : dataSpec.length;
        if (bytesRemaining < 0) {
            throw new EOFException();
        }

    } catch (IOException e) {
        throw new FileDataSourceException(e);
    }

    opened = true;
    if (listener != null) {
        listener.onTransferStart(this, dataSpec);
    }

    return bytesRemaining;
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:26,代码来源:Encrypted1FileDataSource.java

示例3: startLoading

private void startLoading() {
  ExtractingLoadable loadable = new ExtractingLoadable(uri, dataSource, extractorHolder,
      loadCondition);
  if (prepared) {
    Assertions.checkState(isPendingReset());
    if (durationUs != C.TIME_UNSET && pendingResetPositionUs >= durationUs) {
      loadingFinished = true;
      pendingResetPositionUs = C.TIME_UNSET;
      return;
    }
    loadable.setLoadPosition(seekMap.getPosition(pendingResetPositionUs), pendingResetPositionUs);
    pendingResetPositionUs = C.TIME_UNSET;
  }
  extractedSamplesCountAtStartOfLoad = getExtractedSamplesCount();

  int minRetryCount = minLoadableRetryCount;
  if (minRetryCount == ExtractorMediaSource.MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA) {
    // We assume on-demand before we're prepared.
    minRetryCount = !prepared || length != C.LENGTH_UNSET
        || (seekMap != null && seekMap.getDurationUs() != C.TIME_UNSET)
        ? ExtractorMediaSource.DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND
        : ExtractorMediaSource.DEFAULT_MIN_LOADABLE_RETRY_COUNT_LIVE;
  }
  loader.startLoading(loadable, this, minRetryCount);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:25,代码来源:ExtractorMediaPeriod.java

示例4: executePost

private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:17,代码来源:HttpMediaDrmCallback.java

示例5: maybeResyncToNextLevel1Element

/**
 * Does a byte by byte search to try and find the next level 1 element. This method is called if
 * some invalid data is encountered in the parser.
 *
 * @param input The {@link ExtractorInput} from which data has to be read.
 * @return id of the next level 1 element that has been found.
 * @throws EOFException If the end of input was encountered when searching for the next level 1
 *     element.
 * @throws IOException If an error occurs reading from the input.
 * @throws InterruptedException If the thread is interrupted.
 */
private long maybeResyncToNextLevel1Element(ExtractorInput input) throws IOException,
    InterruptedException {
  input.resetPeekPosition();
  while (true) {
    input.peekFully(scratch, 0, MAX_ID_BYTES);
    int varintLength = VarintReader.parseUnsignedVarintLength(scratch[0]);
    if (varintLength != C.LENGTH_UNSET && varintLength <= MAX_ID_BYTES) {
      int potentialId = (int) VarintReader.assembleVarint(scratch, varintLength, false);
      if (output.isLevel1Element(potentialId)) {
        input.skipFully(varintLength);
        return potentialId;
      }
    }
    input.skipFully(1);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:DefaultEbmlReader.java

示例6: open

@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    uri = dataSpec.uri;
    flags = dataSpec.flags;
    key = CacheUtil.getKey(dataSpec);
    readPosition = dataSpec.position;
    currentRequestIgnoresCache = (ignoreCacheOnError && seenCacheError)
        || (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests);
    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = cache.getContentLength(key);
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(true);
    return bytesRemaining;
  } catch (IOException e) {
    handleBeforeThrow(e);
    throw e;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:CacheDataSource.java

示例7: open

@Override
public long open(DataSpec dataSpec) throws AssetDataSourceException {
  try {
    uri = dataSpec.uri;
    String path = uri.getPath();
    if (path.startsWith("/android_asset/")) {
      path = path.substring(15);
    } else if (path.startsWith("/")) {
      path = path.substring(1);
    }
    inputStream = assetManager.open(path, AssetManager.ACCESS_RANDOM);
    long skipped = inputStream.skip(dataSpec.position);
    if (skipped < dataSpec.position) {
      // assetManager.open() returns an AssetInputStream, whose skip() implementation only skips
      // fewer bytes than requested if the skip is beyond the end of the asset's data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNSET) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = inputStream.available();
      if (bytesRemaining == Integer.MAX_VALUE) {
        // assetManager.open() returns an AssetInputStream, whose available() implementation
        // returns Integer.MAX_VALUE if the remaining length is greater than (or equal to)
        // Integer.MAX_VALUE. We don't know the true length in this case, so treat as unbounded.
        bytesRemaining = C.LENGTH_UNSET;
      }
    }
  } catch (IOException e) {
    throw new AssetDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart(this, dataSpec);
  }
  return bytesRemaining;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:38,代码来源:AssetDataSource.java

示例8: readUnsignedVarint

/**
 * Reads an EBML variable-length integer (varint) from an {@link ExtractorInput} such that
 * reading can be resumed later if an error occurs having read only some of it.
 * <p>
 * If an value is successfully read, then the reader will automatically reset itself ready to
 * read another value.
 * <p>
 * If an {@link IOException} or {@link InterruptedException} is throw, the read can be resumed
 * later by calling this method again, passing an {@link ExtractorInput} providing data starting
 * where the previous one left off.
 *
 * @param input The {@link ExtractorInput} from which the integer should be read.
 * @param allowEndOfInput True if encountering the end of the input having read no data is
 *     allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it
 *     should be considered an error, causing an {@link EOFException} to be thrown.
 * @param removeLengthMask Removes the variable-length integer length mask from the value.
 * @param maximumAllowedLength Maximum allowed length of the variable integer to be read.
 * @return The read value, or {@link C#RESULT_END_OF_INPUT} if {@code allowEndOfStream} is true
 *     and the end of the input was encountered, or {@link C#RESULT_MAX_LENGTH_EXCEEDED} if the
 *     length of the varint exceeded maximumAllowedLength.
 * @throws IOException If an error occurs reading from the input.
 * @throws InterruptedException If the thread is interrupted.
 */
public long readUnsignedVarint(ExtractorInput input, boolean allowEndOfInput,
    boolean removeLengthMask, int maximumAllowedLength) throws IOException, InterruptedException {
  if (state == STATE_BEGIN_READING) {
    // Read the first byte to establish the length.
    if (!input.readFully(scratch, 0, 1, allowEndOfInput)) {
      return C.RESULT_END_OF_INPUT;
    }
    int firstByte = scratch[0] & 0xFF;
    length = parseUnsignedVarintLength(firstByte);
    if (length == C.LENGTH_UNSET) {
      throw new IllegalStateException("No valid varint length mask found");
    }
    state = STATE_READ_CONTENTS;
  }

  if (length > maximumAllowedLength) {
    state = STATE_BEGIN_READING;
    return C.RESULT_MAX_LENGTH_EXCEEDED;
  }

  if (length != 1) {
    // Read the remaining bytes.
    input.readFully(scratch, 1, length - 1);
  }

  state = STATE_BEGIN_READING;
  return assembleVarint(scratch, length, removeLengthMask);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:51,代码来源:VarintReader.java

示例9: readSample

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,代码行数:40,代码来源:Mp3Extractor.java

示例10: maybeTerminateInputStream

/**
 * On platform API levels 19 and 20, okhttp's implementation of {@link InputStream#close} can
 * block for a long time if the stream has a lot of data remaining. Call this method before
 * closing the input stream to make a best effort to cause the input stream to encounter an
 * unexpected end of input, working around this issue. On other platform API levels, the method
 * does nothing.
 *
 * @param connection The connection whose {@link InputStream} should be terminated.
 * @param bytesRemaining The number of bytes remaining to be read from the input stream if its
 *     length is known. {@link C#LENGTH_UNSET} otherwise.
 */
private static void maybeTerminateInputStream(HttpURLConnection connection, long bytesRemaining) {
  if (Util.SDK_INT != 19 && Util.SDK_INT != 20) {
    return;
  }

  try {
    InputStream inputStream = connection.getInputStream();
    if (bytesRemaining == C.LENGTH_UNSET) {
      // If the input stream has already ended, do nothing. The socket may be re-used.
      if (inputStream.read() == -1) {
        return;
      }
    } else if (bytesRemaining <= MAX_BYTES_TO_DRAIN) {
      // There isn't much data left. Prefer to allow it to drain, which may allow the socket to be
      // re-used.
      return;
    }
    String className = inputStream.getClass().getName();
    if (className.equals("com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream")
        || className.equals(
        "com.android.okhttp.internal.http.HttpTransport$FixedLengthInputStream")) {
      Class<?> superclass = inputStream.getClass().getSuperclass();
      Method unexpectedEndOfInput = superclass.getDeclaredMethod("unexpectedEndOfInput");
      unexpectedEndOfInput.setAccessible(true);
      unexpectedEndOfInput.invoke(inputStream);
    }
  } catch (Exception e) {
    // If an IOException then the connection didn't ever have an input stream, or it was closed
    // already. If another type of exception then something went wrong, most likely the device
    // isn't using okhttp.
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:43,代码来源:DefaultHttpDataSource.java

示例11: open

@Override
public long open(DataSpec dataSpec) throws IOException {
  uri = dataSpec.uri;
  readPosition = (int) dataSpec.position;
  bytesRemaining = (int) ((dataSpec.length == C.LENGTH_UNSET)
      ? (data.length - dataSpec.position) : dataSpec.length);
  if (bytesRemaining <= 0 || readPosition + bytesRemaining > data.length) {
    throw new IOException("Unsatisfiable range: [" + readPosition + ", " + dataSpec.length
        + "], length: " + data.length);
  }
  return bytesRemaining;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:12,代码来源:ByteArrayDataSource.java

示例12: consumeTestData

private static void consumeTestData(Extractor extractor, FakeExtractorInput input, long timeUs,
    FakeExtractorOutput output, boolean retryFromStartIfLive)
    throws IOException, InterruptedException {
  extractor.seek(input.getPosition(), timeUs);
  PositionHolder seekPositionHolder = new PositionHolder();
  int readResult = Extractor.RESULT_CONTINUE;
  while (readResult != Extractor.RESULT_END_OF_INPUT) {
    try {
      // Extractor.read should not read seekPositionHolder.position. Set it to a value that's
      // likely to cause test failure if a read does occur.
      seekPositionHolder.position = Long.MIN_VALUE;
      readResult = extractor.read(input, seekPositionHolder);
      if (readResult == Extractor.RESULT_SEEK) {
        long seekPosition = seekPositionHolder.position;
        Assertions.checkState(0 <= seekPosition && seekPosition <= Integer.MAX_VALUE);
        input.setPosition((int) seekPosition);
      }
    } catch (SimulatedIOException e) {
      if (!retryFromStartIfLive) {
        continue;
      }
      boolean isOnDemand = input.getLength() != C.LENGTH_UNSET
          || (output.seekMap != null && output.seekMap.getDurationUs() != C.TIME_UNSET);
      if (isOnDemand) {
        continue;
      }
      input.setPosition(0);
      for (int i = 0; i < output.numberOfTracks; i++) {
        output.trackOutputs.valueAt(i).clear();
      }
      extractor.seek(0, 0);
    }
  }
}
 
开发者ID:ashwanijanghu,项目名称:ExoPlayer-Offline,代码行数:34,代码来源:TestUtil.java

示例13: getBytesToRead

private int getBytesToRead(int bytesToRead) {
    if (mBytesRemaining == C.LENGTH_UNSET) {
        return bytesToRead;
    }
    return (int) Math.min(mBytesRemaining, bytesToRead);
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:6,代码来源:EncryptedFileDataSource.java

示例14: getLength

@Override
public long getLength() {
  return simulateUnknownLength ? C.LENGTH_UNSET : data.length;
}
 
开发者ID:ashwanijanghu,项目名称:ExoPlayer-Offline,代码行数:4,代码来源:FakeExtractorInput.java

示例15: createOpenHole

public static SimpleCacheSpan createOpenHole(String key, long position) {
  return new SimpleCacheSpan(key, position, C.LENGTH_UNSET, C.TIME_UNSET, null);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:3,代码来源:SimpleCacheSpan.java


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