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


Java C.LENGTH_UNBOUNDED属性代码示例

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


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

示例1: read

@Override
public int read(byte[] buffer, int offset, int readLength) throws ContentDataSourceException {
  if (bytesRemaining == 0) {
    return -1;
  } else {
    int bytesRead = 0;
    try {
      int bytesToRead = bytesRemaining == C.LENGTH_UNBOUNDED ? readLength
          : (int) Math.min(bytesRemaining, readLength);
      bytesRead = inputStream.read(buffer, offset, bytesToRead);
    } catch (IOException e) {
      throw new ContentDataSourceException(e);
    }

    if (bytesRead > 0) {
      if (bytesRemaining != C.LENGTH_UNBOUNDED) {
        bytesRemaining -= bytesRead;
      }
      if (listener != null) {
        listener.onBytesTransferred(bytesRead);
      }
    }

    return bytesRead;
  }
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:26,代码来源:ContentDataSource.java

示例2: readInternal

/**
 * Reads up to {@code length} bytes of data and stores them into {@code buffer}, starting at
 * index {@code offset}.
 * <p>
 * This method blocks until at least one byte of data can be read, the end of the opened range is
 * detected, or an exception is thrown.
 *
 * @param buffer     The buffer into which the read data should be stored.
 * @param offset     The start offset into {@code buffer} at which data should be written.
 * @param readLength The maximum number of bytes to read.
 * @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if the end of the opened
 * range is reached.
 * @throws IOException If an error occurs reading from the source.
 */
private int readInternal(byte[] buffer, int offset, int readLength) throws IOException {
	readLength = bytesToRead == C.LENGTH_UNBOUNDED ? readLength
			: (int) Math.min(readLength, bytesToRead - bytesRead);
	if (readLength == 0) {
		// We've read all of the requested data.
		return C.RESULT_END_OF_INPUT;
	}

	int read = responseByteStream.read(buffer, offset, readLength);
	if (read == -1) {
		if (bytesToRead != C.LENGTH_UNBOUNDED && bytesToRead != bytesRead) {
			// The server closed the connection having not sent sufficient data.
			throw new EOFException();
		}
		return C.RESULT_END_OF_INPUT;
	}

	bytesRead += read;
	if (listener != null) {
		listener.onBytesTransferred(read);
	}
	return read;
}
 
开发者ID:saeednt,项目名称:ExoCacheDataSource,代码行数:37,代码来源:OkHttpDataSource.java

示例3: readInternal

/**
 * Reads up to {@code length} bytes of data and stores them into {@code buffer}, starting at
 * index {@code offset}.
 * <p>
 * This method blocks until at least one byte of data can be read, the end of the opened range is
 * detected, or an exception is thrown.
 *
 * @param buffer The buffer into which the read data should be stored.
 * @param offset The start offset into {@code buffer} at which data should be written.
 * @param readLength The maximum number of bytes to read.
 * @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if the end of the opened
 *     range is reached.
 * @throws IOException If an error occurs reading from the source.
 */
private int readInternal(byte[] buffer, int offset, int readLength) throws IOException {
    readLength = bytesToRead == C.LENGTH_UNBOUNDED ? readLength
            : (int) Math.min(readLength, bytesToRead - bytesRead);
    if (readLength == 0) {
        // We've read all of the requested data.
        return C.RESULT_END_OF_INPUT;
    }

    int read = responseByteStream.read(buffer, offset, readLength);
    if (read == -1) {
        if (bytesToRead != C.LENGTH_UNBOUNDED && bytesToRead != bytesRead) {
            // The server closed the connection having not sent sufficient data.
            throw new EOFException();
        }
        return C.RESULT_END_OF_INPUT;
    }

    bytesRead += read;
    if (listener != null) {
        listener.onBytesTransferred(read);
    }
    return read;
}
 
开发者ID:ayaseruri,项目名称:luxunPro,代码行数:37,代码来源:OkHttpDataSource.java

示例4: read

@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNBOUNDED ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNBOUNDED || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:24,代码来源:WebvttExtractor.java

示例5: makeRequest

/**
 * Establishes a connection.
 */
private Request makeRequest(DataSpec dataSpec) {
	long position = dataSpec.position;
	long length = dataSpec.length;
	boolean allowGzip = (dataSpec.flags & DataSpec.FLAG_ALLOW_GZIP) != 0;

	HttpUrl url = HttpUrl.parse(dataSpec.uri.toString());
	Request.Builder builder = new Request.Builder().url(url);
	if (cacheControl != null) {
		builder.cacheControl(cacheControl);
	}
	synchronized (requestProperties) {
		for (Map.Entry<String, String> property : requestProperties.entrySet()) {
			builder.addHeader(property.getKey(), property.getValue());
		}
	}
	if (!(position == 0 && length == C.LENGTH_UNBOUNDED)) {
		String rangeRequest = "bytes=" + position + "-";
		if (length != C.LENGTH_UNBOUNDED) {
			rangeRequest += (position + length - 1);
		}
		builder.addHeader("Range", rangeRequest);
	}
	builder.addHeader("User-Agent", userAgent);
	if (!allowGzip) {
		builder.addHeader("Accept-Encoding", "identity");
	}
	if (dataSpec.postBody != null) {
		builder.post(RequestBody.create(null, dataSpec.postBody));
	}
	return builder.build();
}
 
开发者ID:saeednt,项目名称:ExoCacheDataSource,代码行数:34,代码来源:OkHttpDataSource.java

示例6: open

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

示例7: load

@Override
public void load() throws IOException, InterruptedException {
  int result = Extractor.RESULT_CONTINUE;
  while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
    ExtractorInput input = null;
    try {
      long position = positionHolder.position;
      long length = dataSource.open(new DataSpec(uri, position, C.LENGTH_UNBOUNDED, null));
      if (length != C.LENGTH_UNBOUNDED) {
        length += position;
      }
      input = new DefaultExtractorInput(dataSource, position, length);
      Extractor extractor = extractorHolder.selectExtractor(input);
      if (pendingExtractorSeek) {
        extractor.seek();
        pendingExtractorSeek = false;
      }
      while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
        allocator.blockWhileTotalBytesAllocatedExceeds(requestedBufferSize);
        result = extractor.read(input, positionHolder);
        // TODO: Implement throttling to stop us from buffering data too often.
      }
    } finally {
      if (result == Extractor.RESULT_SEEK) {
        result = Extractor.RESULT_CONTINUE;
      } else if (input != null) {
        positionHolder.position = input.getPosition();
      }
      dataSource.close();
    }
  }
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:32,代码来源:ExtractorSampleSource.java

示例8: getRemainderDataSpec

/**
 * Given a {@link DataSpec} and a number of bytes already loaded, returns a {@link DataSpec}
 * that represents the remainder of the data.
 *
 * @param dataSpec The original {@link DataSpec}.
 * @param bytesLoaded The number of bytes already loaded.
 * @return A {@link DataSpec} that represents the remainder of the data.
 */
public static DataSpec getRemainderDataSpec(DataSpec dataSpec, int bytesLoaded) {
  if (bytesLoaded == 0) {
    return dataSpec;
  } else {
    long remainingLength = dataSpec.length == C.LENGTH_UNBOUNDED ? C.LENGTH_UNBOUNDED
        : dataSpec.length - bytesLoaded;
    return new DataSpec(dataSpec.uri, dataSpec.position + bytesLoaded, remainingLength,
        dataSpec.key, dataSpec.flags);
  }
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:18,代码来源:Util.java

示例9: newMediaPlaylistChunk

private MediaPlaylistChunk newMediaPlaylistChunk(int variantIndex) {
  Uri mediaPlaylistUri = UriUtil.resolveToUri(baseUri, variants[variantIndex].url);
  DataSpec dataSpec = new DataSpec(mediaPlaylistUri, 0, C.LENGTH_UNBOUNDED, null,
      DataSpec.FLAG_ALLOW_GZIP);
  return new MediaPlaylistChunk(dataSource, dataSpec, scratchSpace, playlistParser, variantIndex,
      mediaPlaylistUri.toString());
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:7,代码来源:HlsChunkSource.java

示例10: open

@Override
public long open(DataSpec dataSpec) throws AssetDataSourceException {
  try {
    uriString = dataSpec.uri.toString();
    String path = dataSpec.uri.getPath();
    if (path.startsWith("/android_asset/")) {
      path = path.substring(15);
    } else if (path.startsWith("/")) {
      path = path.substring(1);
    }
    uriString = dataSpec.uri.toString();
    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_UNBOUNDED) {
      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_UNBOUNDED;
      }
    }
  } catch (IOException e) {
    throw new AssetDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart();
  }
  return bytesRemaining;
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:39,代码来源:AssetDataSource.java

示例11: open

@Override
public DataSink open(DataSpec dataSpec) throws IOException {
  if (dataSpec.length == C.LENGTH_UNBOUNDED) {
    stream = new ByteArrayOutputStream();
  } else {
    Assertions.checkArgument(dataSpec.length <= Integer.MAX_VALUE);
    stream = new ByteArrayOutputStream((int) dataSpec.length);
  }
  return this;
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:10,代码来源:ByteArrayDataSink.java

示例12: isSeekable

@Override
public boolean isSeekable() {
  return vorbisSetup != null && inputLength != C.LENGTH_UNBOUNDED;
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:4,代码来源:VorbisReader.java

示例13: populatePageHeader

/**
 * Peeks an Ogg page header and stores the data in the {@code header} object passed
 * as argument.
 *
 * @param input the {@link ExtractorInput} to read from.
 * @param header the {@link PageHeader} to read from.
 * @param scratch a scratch array temporary use. Its size should be at least PAGE_HEADER_SIZE
 * @param quite if {@code true} no Exceptions are thrown but {@code false} is return if something
 *     goes wrong.
 * @return {@code true} if the read was successful. {@code false} if the end of the
 *     input was encountered having read no data.
 * @throws IOException thrown if reading data fails or the stream is invalid.
 * @throws InterruptedException thrown if thread is interrupted when reading/peeking.
 */
public static boolean populatePageHeader(ExtractorInput input, PageHeader header,
    ParsableByteArray scratch, boolean quite) throws IOException, InterruptedException {

  scratch.reset();
  header.reset();
  boolean hasEnoughBytes = input.getLength() == C.LENGTH_UNBOUNDED
      || input.getLength() - input.getPeekPosition() >= PAGE_HEADER_SIZE;
  if (!hasEnoughBytes || !input.peekFully(scratch.data, 0, PAGE_HEADER_SIZE, true)) {
    if (quite) {
      return false;
    } else {
      throw new EOFException();
    }
  }
  if (scratch.readUnsignedInt() != TYPE_OGGS) {
    if (quite) {
      return false;
    } else {
      throw new ParserException("expected OggS capture pattern at begin of page");
    }
  }

  header.revision = scratch.readUnsignedByte();
  if (header.revision != 0x00) {
    if (quite) {
      return false;
    } else {
      throw new ParserException("unsupported bit stream revision");
    }
  }
  header.type = scratch.readUnsignedByte();

  header.granulePosition = scratch.readLittleEndianLong();
  header.streamSerialNumber = scratch.readLittleEndianUnsignedInt();
  header.pageSequenceNumber = scratch.readLittleEndianUnsignedInt();
  header.pageChecksum = scratch.readLittleEndianUnsignedInt();
  header.pageSegmentCount = scratch.readUnsignedByte();

  scratch.reset();
  // calculate total size of header including laces
  header.headerSize = PAGE_HEADER_SIZE + header.pageSegmentCount;
  input.peekFully(scratch.data, 0, header.pageSegmentCount);
  for (int i = 0; i < header.pageSegmentCount; i++) {
    header.laces[i] = scratch.readUnsignedByte();
    header.bodySize += header.laces[i];
  }
  return true;
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:62,代码来源:OggUtil.java

示例14: newEncryptionKeyChunk

private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex) {
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNBOUNDED, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(dataSource, dataSpec, scratchSpace, iv, variantIndex);
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:4,代码来源:HlsChunkSource.java

示例15: create

/**
 * Returns a {@link VbriSeeker} 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
 *     'VBRI' 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 VbriSeeker} for seeking in the stream, or {@code null} if the required
 *     information is not present.
 */
public static VbriSeeker create(MpegAudioHeader mpegAudioHeader, ParsableByteArray frame,
    long position, long inputLength) {
  frame.skipBytes(10);
  int numFrames = frame.readInt();
  if (numFrames <= 0) {
    return null;
  }
  int sampleRate = mpegAudioHeader.sampleRate;
  long durationUs = Util.scaleLargeTimestamp(numFrames,
      C.MICROS_PER_SECOND * (sampleRate >= 32000 ? 1152 : 576), sampleRate);
  int entryCount = frame.readUnsignedShort();
  int scale = frame.readUnsignedShort();
  int entrySize = frame.readUnsignedShort();
  frame.skipBytes(2);

  // Skip the frame containing the VBRI header.
  position += mpegAudioHeader.frameSize;

  // Read table of contents entries.
  long[] timesUs = new long[entryCount + 1];
  long[] positions = new long[entryCount + 1];
  timesUs[0] = 0L;
  positions[0] = position;
  for (int index = 1; index < timesUs.length; index++) {
    int segmentSize;
    switch (entrySize) {
      case 1:
        segmentSize = frame.readUnsignedByte();
        break;
      case 2:
        segmentSize = frame.readUnsignedShort();
        break;
      case 3:
        segmentSize = frame.readUnsignedInt24();
        break;
      case 4:
        segmentSize = frame.readUnsignedIntToInt();
        break;
      default:
        return null;
    }
    position += segmentSize * scale;
    timesUs[index] = index * durationUs / entryCount;
    positions[index] =
        inputLength == C.LENGTH_UNBOUNDED ? position : Math.min(inputLength, position);
  }
  return new VbriSeeker(timesUs, positions, durationUs);
}
 
开发者ID:asifkhan11,项目名称:ExoPlayer-Demo,代码行数:61,代码来源:VbriSeeker.java


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