Java Code Examples for com.google.android.exoplayer2.Timeline#getIndexOfPeriod()

The following examples show how to use com.google.android.exoplayer2.Timeline#getIndexOfPeriod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultPlaybackSessionManager.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private int resolveWindowIndexToNewTimeline(
    Timeline oldTimeline, Timeline newTimeline, int windowIndex) {
  if (windowIndex >= oldTimeline.getWindowCount()) {
    return windowIndex < newTimeline.getWindowCount() ? windowIndex : C.INDEX_UNSET;
  }
  oldTimeline.getWindow(windowIndex, window);
  for (int periodIndex = window.firstPeriodIndex;
      periodIndex <= window.lastPeriodIndex;
      periodIndex++) {
    Object periodUid = oldTimeline.getUidOfPeriod(periodIndex);
    int newPeriodIndex = newTimeline.getIndexOfPeriod(periodUid);
    if (newPeriodIndex != C.INDEX_UNSET) {
      return newTimeline.getPeriod(newPeriodIndex, period).windowIndex;
    }
  }
  return C.INDEX_UNSET;
}
 
Example 2
Source File: AnalyticsCollector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: DefaultPlaybackSessionManager.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public boolean tryResolvingToNewTimeline(Timeline oldTimeline, Timeline newTimeline) {
  windowIndex = resolveWindowIndexToNewTimeline(oldTimeline, newTimeline, windowIndex);
  if (windowIndex == C.INDEX_UNSET) {
    return false;
  }
  if (adMediaPeriodId == null) {
    return true;
  }
  int newPeriodIndex = newTimeline.getIndexOfPeriod(adMediaPeriodId.periodUid);
  return newPeriodIndex != C.INDEX_UNSET;
}
 
Example 4
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private WindowAndMediaPeriodId updateMediaPeriodToNewTimeline(
    WindowAndMediaPeriodId mediaPeriod, Timeline newTimeline) {
  if (newTimeline.isEmpty() || timeline.isEmpty()) {
    return mediaPeriod;
  }
  Object uid = timeline.getUidOfPeriod(mediaPeriod.mediaPeriodId.periodIndex);
  int newPeriodIndex = newTimeline.getIndexOfPeriod(uid);
  if (newPeriodIndex == C.INDEX_UNSET) {
    return mediaPeriod;
  }
  int newWindowIndex = newTimeline.getPeriod(newPeriodIndex, period).windowIndex;
  return new WindowAndMediaPeriodId(
      newWindowIndex, mediaPeriod.mediaPeriodId.copyWithPeriodIndex(newPeriodIndex));
}
 
Example 5
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private WindowAndMediaPeriodId updateMediaPeriodToNewTimeline(
    WindowAndMediaPeriodId mediaPeriod, Timeline newTimeline) {
  if (newTimeline.isEmpty() || timeline.isEmpty()) {
    return mediaPeriod;
  }
  Object uid = timeline.getUidOfPeriod(mediaPeriod.mediaPeriodId.periodIndex);
  int newPeriodIndex = newTimeline.getIndexOfPeriod(uid);
  if (newPeriodIndex == C.INDEX_UNSET) {
    return mediaPeriod;
  }
  int newWindowIndex = newTimeline.getPeriod(newPeriodIndex, period).windowIndex;
  return new WindowAndMediaPeriodId(
      newWindowIndex, mediaPeriod.mediaPeriodId.copyWithPeriodIndex(newPeriodIndex));
}
 
Example 6
Source File: AnalyticsCollector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: AnalyticsCollector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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);
}