Java 类com.google.android.exoplayer.text.webvtt.WebvttParser 实例源码

项目:android-exoplayer    文件:DashChunkSource.java   
private Chunk newMediaChunk(RepresentationHolder representationHolder, DataSource dataSource,
    int segmentNum, int trigger) {
  Representation representation = representationHolder.representation;
  DashSegmentIndex segmentIndex = representationHolder.segmentIndex;

  long startTimeUs = segmentIndex.getTimeUs(segmentNum);
  long endTimeUs = startTimeUs + segmentIndex.getDurationUs(segmentNum);

  boolean isLastSegment = !currentManifest.dynamic
      && segmentNum == segmentIndex.getLastSegmentNum();
  int nextAbsoluteSegmentNum = isLastSegment ? -1
      : (representationHolder.segmentNumShift + segmentNum + 1);

  RangedUri segmentUri = segmentIndex.getSegmentUrl(segmentNum);
  DataSpec dataSpec = new DataSpec(segmentUri.getUri(), segmentUri.start, segmentUri.length,
      representation.getCacheKey());

  long presentationTimeOffsetUs = representation.presentationTimeOffsetMs * 1000;
  if (representation.format.mimeType.equals(MimeTypes.TEXT_VTT)) {
    if (representationHolder.vttHeaderOffsetUs != presentationTimeOffsetUs) {
      // Update the VTT header.
      headerBuilder.setLength(0);
      headerBuilder.append(WebvttParser.EXO_HEADER).append("=")
          .append(WebvttParser.OFFSET).append(presentationTimeOffsetUs).append("\n");
      representationHolder.vttHeader = headerBuilder.toString().getBytes();
      representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs;
    }
    return new SingleSampleMediaChunk(dataSource, dataSpec, representation.format, 0,
        startTimeUs, endTimeUs, nextAbsoluteSegmentNum, null, representationHolder.vttHeader);
  } else {
    return new Mp4MediaChunk(dataSource, dataSpec, representation.format, trigger, startTimeUs,
        endTimeUs, nextAbsoluteSegmentNum, representationHolder.extractor, psshInfo, false,
        presentationTimeOffsetUs);
  }
}
项目:Exoplayer_VLC    文件:DashChunkSource.java   
private Chunk newMediaChunk(RepresentationHolder representationHolder, DataSource dataSource,
    int segmentNum, int trigger) {
  Representation representation = representationHolder.representation;
  DashSegmentIndex segmentIndex = representationHolder.segmentIndex;

  long startTimeUs = segmentIndex.getTimeUs(segmentNum);
  long endTimeUs = startTimeUs + segmentIndex.getDurationUs(segmentNum);

  boolean isLastSegment = !currentManifest.dynamic
      && segmentNum == segmentIndex.getLastSegmentNum();
  int nextAbsoluteSegmentNum = isLastSegment ? -1
      : (representationHolder.segmentNumShift + segmentNum + 1);

  RangedUri segmentUri = segmentIndex.getSegmentUrl(segmentNum);
  DataSpec dataSpec = new DataSpec(segmentUri.getUri(), segmentUri.start, segmentUri.length,
      representation.getCacheKey());

  long presentationTimeOffsetUs = representation.presentationTimeOffsetUs;
  if (representation.format.mimeType.equals(MimeTypes.TEXT_VTT)) {
    if (representationHolder.vttHeaderOffsetUs != presentationTimeOffsetUs) {
      // Update the VTT header.
      headerBuilder.setLength(0);
      headerBuilder.append(WebvttParser.EXO_HEADER).append("=")
          .append(WebvttParser.OFFSET).append(presentationTimeOffsetUs).append("\n");
      representationHolder.vttHeader = headerBuilder.toString().getBytes();
      representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs;
    }
    return new SingleSampleMediaChunk(dataSource, dataSpec, representation.format, 0,
        startTimeUs, endTimeUs, nextAbsoluteSegmentNum, null, representationHolder.vttHeader);
  } else {
    return new ContainerMediaChunk(dataSource, dataSpec, representation.format, trigger,
        startTimeUs, endTimeUs, nextAbsoluteSegmentNum, representationHolder.extractor, psshInfo,
        false, presentationTimeOffsetUs);
  }
}