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

The following examples show how to use com.google.android.exoplayer2.Timeline#getPeriodCount() . 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: 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 2
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 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: ConcatenatingMediaSource.java    From K-Sonic with MIT License 6 votes vote down vote up
public ConcatenatedTimeline(Timeline[] timelines) {
  int[] sourcePeriodOffsets = new int[timelines.length];
  int[] sourceWindowOffsets = new int[timelines.length];
  int periodCount = 0;
  int windowCount = 0;
  for (int i = 0; i < timelines.length; i++) {
    Timeline timeline = timelines[i];
    periodCount += timeline.getPeriodCount();
    sourcePeriodOffsets[i] = periodCount;
    windowCount += timeline.getWindowCount();
    sourceWindowOffsets[i] = windowCount;
  }
  this.timelines = timelines;
  this.sourcePeriodOffsets = sourcePeriodOffsets;
  this.sourceWindowOffsets = sourceWindowOffsets;
}
 
Example 5
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 6
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 7
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 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.
 * @throws IllegalClippingException If the timeline could not be clipped.
 */
public ClippingTimeline(Timeline timeline, long startUs, long endUs)
    throws IllegalClippingException {
  super(timeline);
  if (timeline.getPeriodCount() != 1) {
    throw new IllegalClippingException(IllegalClippingException.REASON_INVALID_PERIOD_COUNT);
  }
  Window window = timeline.getWindow(0, new Window(), false);
  startUs = Math.max(0, startUs);
  long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs);
  if (window.durationUs != C.TIME_UNSET) {
    if (resolvedEndUs > window.durationUs) {
      resolvedEndUs = window.durationUs;
    }
    if (startUs != 0 && !window.isSeekable) {
      throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
    }
    if (startUs > resolvedEndUs) {
      throw new IllegalClippingException(IllegalClippingException.REASON_START_EXCEEDS_END);
    }
  }
  this.startUs = startUs;
  this.endUs = resolvedEndUs;
  durationUs = resolvedEndUs == C.TIME_UNSET ? C.TIME_UNSET : (resolvedEndUs - startUs);
  isDynamic =
      window.isDynamic
          && (resolvedEndUs == C.TIME_UNSET
              || (window.durationUs != C.TIME_UNSET && resolvedEndUs == window.durationUs));
}
 
Example 8
Source File: MergingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private IllegalMergeException checkTimelineMerges(Timeline timeline) {
  if (periodCount == PERIOD_COUNT_UNSET) {
    periodCount = timeline.getPeriodCount();
  } else if (timeline.getPeriodCount() != periodCount) {
    return new IllegalMergeException(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
  }
  return null;
}
 
Example 9
Source File: ConcatenatingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public DeferredTimeline cloneWithNewTimeline(Timeline timeline) {
  return new DeferredTimeline(
      timeline,
      replacedId == DUMMY_ID && timeline.getPeriodCount() > 0
          ? timeline.getUidOfPeriod(0)
          : replacedId);
}
 
Example 10
Source File: ConcatenatingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
  if (mediaSourceHolder == null) {
    throw new IllegalArgumentException();
  }
  DeferredTimeline deferredTimeline = mediaSourceHolder.timeline;
  if (deferredTimeline.getTimeline() == timeline) {
    return;
  }
  int windowOffsetUpdate = timeline.getWindowCount() - deferredTimeline.getWindowCount();
  int periodOffsetUpdate = timeline.getPeriodCount() - deferredTimeline.getPeriodCount();
  if (windowOffsetUpdate != 0 || periodOffsetUpdate != 0) {
    correctOffsets(
        mediaSourceHolder.childIndex + 1,
        /* childIndexUpdate= */ 0,
        windowOffsetUpdate,
        periodOffsetUpdate);
  }
  mediaSourceHolder.timeline = deferredTimeline.cloneWithNewTimeline(timeline);
  if (!mediaSourceHolder.isPrepared && !timeline.isEmpty()) {
    timeline.getWindow(/* windowIndex= */ 0, window);
    long defaultPeriodPositionUs =
        window.getPositionInFirstPeriodUs() + window.getDefaultPositionUs();
    for (int i = 0; i < mediaSourceHolder.activeMediaPeriods.size(); i++) {
      DeferredMediaPeriod deferredMediaPeriod = mediaSourceHolder.activeMediaPeriods.get(i);
      deferredMediaPeriod.setDefaultPreparePositionUs(defaultPeriodPositionUs);
      MediaPeriodId idInSource =
          deferredMediaPeriod.id.copyWithPeriodIndex(
              deferredMediaPeriod.id.periodIndex - mediaSourceHolder.firstPeriodIndexInChild);
      deferredMediaPeriod.createPeriod(idInSource);
    }
    mediaSourceHolder.isPrepared = true;
  }
  scheduleListenerNotification(/* actionOnCompletion= */ null);
}
 
Example 11
Source File: LoopingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public LoopingTimeline(Timeline childTimeline, int loopCount) {
  super(/* isAtomic= */ false, new UnshuffledShuffleOrder(loopCount));
  this.childTimeline = childTimeline;
  childPeriodCount = childTimeline.getPeriodCount();
  childWindowCount = childTimeline.getWindowCount();
  this.loopCount = loopCount;
  if (childPeriodCount > 0) {
    Assertions.checkState(loopCount <= Integer.MAX_VALUE / childPeriodCount,
        "LoopingMediaSource contains too many periods");
  }
}
 
Example 12
Source File: LoopingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onChildSourceInfoRefreshed(
    Void id, MediaSource mediaSource, Timeline timeline, @Nullable Object manifest) {
  childPeriodCount = timeline.getPeriodCount();
  Timeline loopingTimeline =
      loopCount != Integer.MAX_VALUE
          ? new LoopingTimeline(timeline, loopCount)
          : new InfinitelyLoopingTimeline(timeline);
  refreshSourceInfo(loopingTimeline, manifest);
}
 
Example 13
Source File: ClippingMediaSource.java    From MediaSDK with Apache License 2.0 5 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.
 * @throws IllegalClippingException If the timeline could not be clipped.
 */
public ClippingTimeline(Timeline timeline, long startUs, long endUs)
    throws IllegalClippingException {
  super(timeline);
  if (timeline.getPeriodCount() != 1) {
    throw new IllegalClippingException(IllegalClippingException.REASON_INVALID_PERIOD_COUNT);
  }
  Window window = timeline.getWindow(0, new Window());
  startUs = Math.max(0, startUs);
  long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs);
  if (window.durationUs != C.TIME_UNSET) {
    if (resolvedEndUs > window.durationUs) {
      resolvedEndUs = window.durationUs;
    }
    if (startUs != 0 && !window.isSeekable) {
      throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
    }
    if (startUs > resolvedEndUs) {
      throw new IllegalClippingException(IllegalClippingException.REASON_START_EXCEEDS_END);
    }
  }
  this.startUs = startUs;
  this.endUs = resolvedEndUs;
  durationUs = resolvedEndUs == C.TIME_UNSET ? C.TIME_UNSET : (resolvedEndUs - startUs);
  isDynamic =
      window.isDynamic
          && (resolvedEndUs == C.TIME_UNSET
              || (window.durationUs != C.TIME_UNSET && resolvedEndUs == window.durationUs));
}
 
Example 14
Source File: MergingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private IllegalMergeException checkTimelineMerges(Timeline timeline) {
  if (periodCount == PERIOD_COUNT_UNSET) {
    periodCount = timeline.getPeriodCount();
  } else if (timeline.getPeriodCount() != periodCount) {
    return new IllegalMergeException(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
  }
  return null;
}
 
Example 15
Source File: LoopingMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public LoopingTimeline(Timeline childTimeline, int loopCount) {
  super(/* isAtomic= */ false, new UnshuffledShuffleOrder(loopCount));
  this.childTimeline = childTimeline;
  childPeriodCount = childTimeline.getPeriodCount();
  childWindowCount = childTimeline.getWindowCount();
  this.loopCount = loopCount;
  if (childPeriodCount > 0) {
    Assertions.checkState(loopCount <= Integer.MAX_VALUE / childPeriodCount,
        "LoopingMediaSource contains too many periods");
  }
}
 
Example 16
Source File: MergingMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
private IllegalMergeException checkTimelineMerges(Timeline timeline) {
  int windowCount = timeline.getWindowCount();
  for (int i = 0; i < windowCount; i++) {
    if (timeline.getWindow(i, window, false).isDynamic) {
      return new IllegalMergeException(IllegalMergeException.REASON_WINDOWS_ARE_DYNAMIC);
    }
  }
  if (periodCount == PERIOD_COUNT_UNSET) {
    periodCount = timeline.getPeriodCount();
  } else if (timeline.getPeriodCount() != periodCount) {
    return new IllegalMergeException(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
  }
  return null;
}
 
Example 17
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 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.
 * @throws IllegalClippingException If the timeline could not be clipped.
 */
public ClippingTimeline(Timeline timeline, long startUs, long endUs)
    throws IllegalClippingException {
  super(timeline);
  if (timeline.getPeriodCount() != 1) {
    throw new IllegalClippingException(IllegalClippingException.REASON_INVALID_PERIOD_COUNT);
  }
  Window window = timeline.getWindow(0, new Window(), false);
  startUs = Math.max(0, startUs);
  long resolvedEndUs = endUs == C.TIME_END_OF_SOURCE ? window.durationUs : Math.max(0, endUs);
  if (window.durationUs != C.TIME_UNSET) {
    if (resolvedEndUs > window.durationUs) {
      resolvedEndUs = window.durationUs;
    }
    if (startUs != 0 && !window.isSeekable) {
      throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
    }
    if (startUs > resolvedEndUs) {
      throw new IllegalClippingException(IllegalClippingException.REASON_START_EXCEEDS_END);
    }
  }
  this.startUs = startUs;
  this.endUs = resolvedEndUs;
  durationUs = resolvedEndUs == C.TIME_UNSET ? C.TIME_UNSET : (resolvedEndUs - startUs);
  isDynamic =
      window.isDynamic
          && (resolvedEndUs == C.TIME_UNSET
              || (window.durationUs != C.TIME_UNSET && resolvedEndUs == window.durationUs));
}
 
Example 18
Source File: MergingMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Nullable
private IllegalMergeException checkTimelineMerges(Timeline timeline) {
  if (periodCount == PERIOD_COUNT_UNSET) {
    periodCount = timeline.getPeriodCount();
  } else if (timeline.getPeriodCount() != periodCount) {
    return new IllegalMergeException(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
  }
  return null;
}
 
Example 19
Source File: LoopingMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public LoopingTimeline(Timeline childTimeline, int loopCount) {
  super(/* isAtomic= */ false, new UnshuffledShuffleOrder(loopCount));
  this.childTimeline = childTimeline;
  childPeriodCount = childTimeline.getPeriodCount();
  childWindowCount = childTimeline.getWindowCount();
  this.loopCount = loopCount;
  if (childPeriodCount > 0) {
    Assertions.checkState(loopCount <= Integer.MAX_VALUE / childPeriodCount,
        "LoopingMediaSource contains too many periods");
  }
}
 
Example 20
Source File: ConcatenatingMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
  if (mediaSourceHolder == null) {
    throw new IllegalArgumentException();
  }
  DeferredTimeline deferredTimeline = mediaSourceHolder.timeline;
  if (deferredTimeline.getTimeline() == timeline) {
    return;
  }
  int windowOffsetUpdate = timeline.getWindowCount() - deferredTimeline.getWindowCount();
  int periodOffsetUpdate = timeline.getPeriodCount() - deferredTimeline.getPeriodCount();
  if (windowOffsetUpdate != 0 || periodOffsetUpdate != 0) {
    correctOffsets(
        mediaSourceHolder.childIndex + 1,
        /* childIndexUpdate= */ 0,
        windowOffsetUpdate,
        periodOffsetUpdate);
  }
  if (mediaSourceHolder.isPrepared) {
    mediaSourceHolder.timeline = deferredTimeline.cloneWithUpdatedTimeline(timeline);
  } else if (timeline.isEmpty()) {
    mediaSourceHolder.timeline =
        DeferredTimeline.createWithRealTimeline(timeline, DeferredTimeline.DUMMY_ID);
  } else {
    // We should have at most one deferred media period for the DummyTimeline because the duration
    // is unset and we don't load beyond periods with unset duration. We need to figure out how to
    // handle the prepare positions of multiple deferred media periods, should that ever change.
    Assertions.checkState(mediaSourceHolder.activeMediaPeriods.size() <= 1);
    DeferredMediaPeriod deferredMediaPeriod =
        mediaSourceHolder.activeMediaPeriods.isEmpty()
            ? null
            : mediaSourceHolder.activeMediaPeriods.get(0);
    // Determine first period and the start position.
    // This will be:
    //  1. The default window start position if no deferred period has been created yet.
    //  2. The non-zero prepare position of the deferred period under the assumption that this is
    //     a non-zero initial seek position in the window.
    //  3. The default window start position if the deferred period has a prepare position of zero
    //     under the assumption that the prepare position of zero was used because it's the
    //     default position of the DummyTimeline window. Note that this will override an
    //     intentional seek to zero for a window with a non-zero default position. This is
    //     unlikely to be a problem as a non-zero default position usually only occurs for live
    //     playbacks and seeking to zero in a live window would cause BehindLiveWindowExceptions
    //     anyway.
    timeline.getWindow(/* windowIndex= */ 0, window);
    long windowStartPositionUs = window.getDefaultPositionUs();
    if (deferredMediaPeriod != null) {
      long periodPreparePositionUs = deferredMediaPeriod.getPreparePositionUs();
      if (periodPreparePositionUs != 0) {
        windowStartPositionUs = periodPreparePositionUs;
      }
    }
    Pair<Object, Long> periodPosition =
        timeline.getPeriodPosition(window, period, /* windowIndex= */ 0, windowStartPositionUs);
    Object periodUid = periodPosition.first;
    long periodPositionUs = periodPosition.second;
    mediaSourceHolder.timeline = DeferredTimeline.createWithRealTimeline(timeline, periodUid);
    if (deferredMediaPeriod != null) {
      deferredMediaPeriod.overridePreparePositionUs(periodPositionUs);
      MediaPeriodId idInSource =
          deferredMediaPeriod.id.copyWithPeriodUid(
              getChildPeriodUid(mediaSourceHolder, deferredMediaPeriod.id.periodUid));
      deferredMediaPeriod.createPeriod(idInSource);
    }
  }
  mediaSourceHolder.isPrepared = true;
  scheduleTimelineUpdate();
}