com.google.android.exoplayer2.Timeline.getPeriod()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中com.google.android.exoplayer2.Timeline.getPeriod()方法的一些代码示例,展示了Timeline.getPeriod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timeline.getPeriod()方法的具体详情如下:
包路径:com.google.android.exoplayer2.Timeline
类名称:Timeline
方法名:getPeriod

Timeline.getPeriod介绍

[英]Populates a Period with data for the period at the specified index. Does not populate Period#id and Period#uid.
[中]用指定索引处的时段数据填充时段。不填充句号#id和句号#uid。

代码示例

代码示例来源:origin: google/ExoPlayer

/**
 * Populates a {@link Period} with data for the period at the specified index. Does not populate
 * {@link Period#id} and {@link Period#uid}.
 *
 * @param periodIndex The index of the period.
 * @param period The {@link Period} to populate. Must not be null.
 * @return The populated {@link Period}, for convenience.
 */
public final Period getPeriod(int periodIndex, Period period) {
 return getPeriod(periodIndex, period, false);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Asserts that the durations of the periods in the {@link Timeline} and the durations in the
 * given sequence are equal.
 */
public static void assertPeriodDurations(Timeline timeline, long... durationsUs) {
 int periodCount = timeline.getPeriodCount();
 assertThat(periodCount).isEqualTo(durationsUs.length);
 Period period = new Period();
 for (int i = 0; i < periodCount; i++) {
  assertThat(timeline.getPeriod(i, period).durationUs).isEqualTo(durationsUs[i]);
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
 return timeline.getPeriod(periodIndex, period, setIds);
}

代码示例来源:origin: google/ExoPlayer

/** Asserts that periods' {@link Period#getAdGroupCount()} are set correctly. */
 public static void assertAdGroupCounts(Timeline timeline, int... expectedAdGroupCounts) {
  Period period = new Period();
  for (int i = 0; i < timeline.getPeriodCount(); i++) {
   timeline.getPeriod(i, period);
   assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]);
  }
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
 timeline.getPeriod(periodIndex, period, setIds);
 if (Util.areEqual(period.uid, replacedId)) {
  period.uid = DUMMY_ID;
 }
 return period;
}

代码示例来源:origin: google/ExoPlayer

/**
 * Asserts that the durations of the periods in the {@link Timeline} and the durations in the
 * given sequence are equal.
 */
public static void assertPeriodDurations(Timeline timeline, long... durationsUs) {
 int periodCount = timeline.getPeriodCount();
 assertThat(periodCount).isEqualTo(durationsUs.length);
 Period period = new Period();
 for (int i = 0; i < periodCount; i++) {
  assertThat(timeline.getPeriod(i, period).durationUs).isEqualTo(durationsUs[i]);
 }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Populates a {@link Period} with data for the period with the specified unique identifier.
 *
 * @param periodUid The unique identifier of the period.
 * @param period The {@link Period} to populate. Must not be null.
 * @return The populated {@link Period}, for convenience.
 */
public Period getPeriodByUid(Object periodUid, Period period) {
 return getPeriod(getIndexOfPeriod(periodUid), period, /* setIds= */ true);
}

代码示例来源:origin: google/ExoPlayer

/** Asserts that periods' {@link Period#getAdGroupCount()} are set correctly. */
 public static void assertAdGroupCounts(Timeline timeline, int... expectedAdGroupCounts) {
  Period period = new Period();
  for (int i = 0; i < timeline.getPeriodCount(); i++) {
   timeline.getPeriod(i, period);
   assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]);
  }
 }
}

代码示例来源:origin: google/ExoPlayer

private static long[][] getAdDurations(Timeline[][] adTimelines, Timeline.Period period) {
 long[][] adDurations = new long[adTimelines.length][];
 for (int i = 0; i < adTimelines.length; i++) {
  adDurations[i] = new long[adTimelines[i].length];
  for (int j = 0; j < adTimelines[i].length; j++) {
   adDurations[i][j] =
     adTimelines[i][j] == null
       ? C.TIME_UNSET
       : adTimelines[i][j].getPeriod(/* periodIndex= */ 0, period).getDurationUs();
  }
 }
 return adDurations;
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testNoClipping() throws IOException {
 Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, true, false);
 Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
 assertThat(clippedTimeline.getWindowCount()).isEqualTo(1);
 assertThat(clippedTimeline.getPeriodCount()).isEqualTo(1);
 assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US);
 assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US);
}

代码示例来源:origin: google/ExoPlayer

private MediaPeriodInfo updateMediaPeriodInfoToNewTimeline(
   MediaPeriodInfo info, Timeline newTimeline) {
  int newPeriodIndex = newTimeline.getIndexOfPeriod(info.mediaPeriodId.periodUid);
  if (newPeriodIndex == C.INDEX_UNSET) {
   // Media period is not yet or no longer available in the new timeline. Keep it as it is.
   return info;
  }
  int newWindowIndex = newTimeline.getPeriod(newPeriodIndex, period).windowIndex;
  return new MediaPeriodInfo(info.mediaPeriodId, newTimeline, newWindowIndex);
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
 timeline.getPeriod(periodIndex, period, setIds);
 period.set(
   period.id,
   period.uid,
   period.windowIndex,
   period.durationUs,
   period.getPositionInWindowUs(),
   adPlaybackState);
 return period;
}

代码示例来源:origin: google/ExoPlayer

@Override
 public Period getPeriod(int periodIndex, Period period, boolean setIds) {
  timeline.getPeriod(/* periodIndex= */ 0, period, setIds);
  long positionInClippedWindowUs = period.getPositionInWindowUs() - startUs;
  long periodDurationUs =
    durationUs == C.TIME_UNSET ? C.TIME_UNSET : durationUs - positionInClippedWindowUs;
  return period.set(
    period.id, period.uid, /* windowIndex= */ 0, periodDurationUs, positionInClippedWindowUs);
 }
}

代码示例来源:origin: google/ExoPlayer

private boolean isLastInTimeline(MediaPeriodId id, boolean isLastMediaPeriodInPeriod) {
  int periodIndex = timeline.getIndexOfPeriod(id.periodUid);
  int windowIndex = timeline.getPeriod(periodIndex, period).windowIndex;
  return !timeline.getWindow(windowIndex, window).isDynamic
    && timeline.isLastPeriod(periodIndex, period, window, repeatMode, shuffleModeEnabled)
    && isLastMediaPeriodInPeriod;
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
 assertThat(preparedSource).isTrue();
 assertThat(releasedSource).isFalse();
 int periodIndex = timeline.getIndexOfPeriod(id.periodUid);
 Assertions.checkArgument(periodIndex != C.INDEX_UNSET);
 Period period = timeline.getPeriod(periodIndex, new Period());
 EventDispatcher eventDispatcher =
   createEventDispatcher(period.windowIndex, id, period.getPositionInWindowMs());
 FakeMediaPeriod mediaPeriod =
   createFakeMediaPeriod(id, trackGroupArray, allocator, eventDispatcher, transferListener);
 activeMediaPeriods.add(mediaPeriod);
 createdMediaPeriods.add(id);
 return mediaPeriod;
}

代码示例来源:origin: google/ExoPlayer

@Override
public final Period getPeriod(int periodIndex, Period period, boolean setIds) {
 int childIndex = getChildIndexByPeriodIndex(periodIndex);
 int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex);
 int firstPeriodIndexInChild = getFirstPeriodIndexByChildIndex(childIndex);
 getTimelineByChildIndex(childIndex).getPeriod(periodIndex - firstPeriodIndexInChild, period,
   setIds);
 period.windowIndex += firstWindowIndexInChild;
 if (setIds) {
  period.uid = getConcatenatedUid(getChildUidByChildIndex(childIndex), period.uid);
 }
 return period;
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testClippingStartAndEnd() throws IOException {
 Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, true, false);
 Timeline clippedTimeline =
   getClippedTimeline(
     timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
 assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
 assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testClippingStart() throws IOException {
 Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, true, false);
 Timeline clippedTimeline =
   getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US);
 assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
 assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US);
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testClippingEnd() throws IOException {
 Timeline timeline = new SinglePeriodTimeline(TEST_PERIOD_DURATION_US, true, false);
 Timeline clippedTimeline =
   getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
 assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
 assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
   .isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
}

代码示例来源:origin: google/ExoPlayer

@Override
public long getDuration() {
 if (timeline.isEmpty()) {
  return C.INDEX_UNSET;
 }
 if (isPlayingAd()) {
  long adDurationUs =
    timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup);
  return C.usToMs(adDurationUs);
 } else {
  return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
 }
}

相关文章