Java 类com.google.android.exoplayer2.source.chunk.ChunkHolder 实例源码

项目:transistor    文件:FakeChunkSource.java   
@Override
public void getNextChunk(MediaChunk previous, long playbackPositionUs, long loadPositionUs,
    ChunkHolder out) {
  long bufferedDurationUs = loadPositionUs - playbackPositionUs;
  trackSelection.updateSelectedTrack(playbackPositionUs, bufferedDurationUs, C.TIME_UNSET);
  int chunkIndex = previous == null ? dataSet.getChunkIndexByPosition(playbackPositionUs)
      : previous.getNextChunkIndex();
  if (chunkIndex >= dataSet.getChunkCount()) {
    out.endOfStream = true;
  } else {
    Format selectedFormat = trackSelection.getSelectedFormat();
    long startTimeUs = dataSet.getStartTime(chunkIndex);
    long endTimeUs = startTimeUs + dataSet.getChunkDuration(chunkIndex);
    int trackGroupIndex = trackSelection.getIndexInTrackGroup(trackSelection.getSelectedIndex());
    String uri = dataSet.getUri(trackGroupIndex);
    Segment fakeDataChunk = dataSet.getData(uri).getSegments().get(chunkIndex);
    DataSpec dataSpec = new DataSpec(Uri.parse(uri), fakeDataChunk.byteOffset,
        fakeDataChunk.length, null);
    int trackType = MimeTypes.getTrackType(selectedFormat.sampleMimeType);
    out.chunk = new SingleSampleMediaChunk(dataSource, dataSpec, selectedFormat,
        trackSelection.getSelectionReason(), trackSelection.getSelectionData(), startTimeUs,
        endTimeUs, chunkIndex, trackType, selectedFormat);
  }
}