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

The following examples show how to use com.google.android.exoplayer2.Timeline#getPeriod() . 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: EventLogger.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
  int periodCount = timeline.getPeriodCount();
  int windowCount = timeline.getWindowCount();
  Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
  for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getPeriod(i, period);
    Log.d(TAG, "  " +  "period [" + getTimeString(period.getDurationMs()) + "]");
  }
  if (periodCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getWindow(i, window);
    Log.d(TAG, "  " +  "window [" + getTimeString(window.getDurationMs()) + ", "
        + window.isSeekable + ", " + window.isDynamic + "]");
  }
  if (windowCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  Log.d(TAG, "]");
}
 
Example 3
Source File: EventLogger.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
  if (timeline == null) {
    return;
  }
  int periodCount = timeline.getPeriodCount();
  int windowCount = timeline.getWindowCount();
  Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
  for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getPeriod(i, period);
    Log.d(TAG, "  " +  "period [" + getTimeString(period.getDurationMs()) + "]");
  }
  if (periodCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getWindow(i, window);
    Log.d(TAG, "  " +  "window [" + getTimeString(window.getDurationMs()) + ", "
        + window.isSeekable + ", " + window.isDynamic + "]");
  }
  if (windowCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  Log.d(TAG, "]");
}
 
Example 4
Source File: EventLogger.java    From LiveVideoBroadcaster with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
  int periodCount = timeline.getPeriodCount();
  int windowCount = timeline.getWindowCount();
  Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
  for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getPeriod(i, period);
    Log.d(TAG, "  " +  "period [" + getTimeString(period.getDurationMs()) + "]");
  }
  if (periodCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getWindow(i, window);
    Log.d(TAG, "  " +  "window [" + getTimeString(window.getDurationMs()) + ", "
        + window.isSeekable + ", " + window.isDynamic + "]");
  }
  if (windowCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  Log.d(TAG, "]");
}
 
Example 5
Source File: EventLogger.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
    int periodCount = timeline.getPeriodCount();
    int windowCount = timeline.getWindowCount();
    Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
    for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
        timeline.getPeriod(i, period);
        Log.d(TAG, "  " + "period [" + getTimeString(period.getDurationMs()) + "]");
    }
    if (periodCount > MAX_TIMELINE_ITEM_LINES) {
        Log.d(TAG, "  ...");
    }
    for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
        timeline.getWindow(i, window);
        Log.d(TAG, "  " + "window [" + getTimeString(window.getDurationMs()) + ", "
                + window.isSeekable + ", " + window.isDynamic + "]");
    }
    if (windowCount > MAX_TIMELINE_ITEM_LINES) {
        Log.d(TAG, "  ...");
    }
    Log.d(TAG, "]");
}
 
Example 6
Source File: EventLogger.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
    int periodCount = timeline.getPeriodCount();
    int windowCount = timeline.getWindowCount();
    Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
    for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
        timeline.getPeriod(i, period);
        Log.d(TAG, "  " + "period [" + getTimeString(period.getDurationMs()) + "]");
    }
    if (periodCount > MAX_TIMELINE_ITEM_LINES) {
        Log.d(TAG, "  ...");
    }
    for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
        timeline.getWindow(i, window);
        Log.d(TAG, "  " + "window [" + getTimeString(window.getDurationMs()) + ", "
                + window.isSeekable + ", " + window.isDynamic + "]");
    }
    if (windowCount > MAX_TIMELINE_ITEM_LINES) {
        Log.d(TAG, "  ...");
    }
    Log.d(TAG, "]");
}
 
Example 7
Source File: ClippingMediaSource.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Creates a new clipping timeline that wraps the specified timeline.
 *
 * @param timeline The timeline to clip.
 * @param startUs The number of microseconds to clip from the start of {@code timeline}.
 * @param endUs The end position in microseconds for the clipped timeline relative to the start
 *     of {@code timeline}, or {@link C#TIME_END_OF_SOURCE} to clip no samples from the end.
 */
public ClippingTimeline(Timeline timeline, long startUs, long endUs) {
  Assertions.checkArgument(timeline.getWindowCount() == 1);
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  Window window = timeline.getWindow(0, new Window(), false);
  Assertions.checkArgument(!window.isDynamic);
  long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : endUs;
  if (window.durationUs != C.TIME_UNSET) {
    Assertions.checkArgument(startUs == 0 || window.isSeekable);
    Assertions.checkArgument(resolvedEndUs <= window.durationUs);
    Assertions.checkArgument(startUs <= resolvedEndUs);
  }
  Period period = timeline.getPeriod(0, new Period());
  Assertions.checkArgument(period.getPositionInWindowUs() == 0);
  this.timeline = timeline;
  this.startUs = startUs;
  this.endUs = resolvedEndUs;
}
 
Example 8
Source File: EventLogger.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
  int periodCount = timeline.getPeriodCount();
  int windowCount = timeline.getWindowCount();
  Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
  for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getPeriod(i, period);
    Log.d(TAG, "  " + "period [" + getTimeString(period.getDurationMs()) + "]");
  }
  if (periodCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getWindow(i, window);
    Log.d(TAG, "  " + "window [" + getTimeString(window.getDurationMs()) + ", "
            + window.isSeekable + ", " + window.isDynamic + "]");
  }
  if (windowCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  Log.d(TAG, "]");
}
 
Example 9
Source File: EventLogger.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
  if (timeline == null) {
    return;
  }
  int periodCount = timeline.getPeriodCount();
  int windowCount = timeline.getWindowCount();
  Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
  for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getPeriod(i, period);
    Log.d(TAG, "  " +  "period [" + getTimeString(period.getDurationMs()) + "]");
  }
  if (periodCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) {
    timeline.getWindow(i, window);
    Log.d(TAG, "  " +  "window [" + getTimeString(window.getDurationMs()) + ", "
            + window.isSeekable + ", " + window.isDynamic + "]");
  }
  if (windowCount > MAX_TIMELINE_ITEM_LINES) {
    Log.d(TAG, "  ...");
  }
  Log.d(TAG, "]");
}
 
Example 10
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 11
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 12
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 13
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 14
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);
}