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

The following examples show how to use com.google.android.exoplayer2.Timeline#getWindowCount() . 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: ConcatenatingMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
  if (mediaSourceHolder == null) {
    throw new IllegalArgumentException();
  }
  if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) {
    MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1);
    int windowOffsetUpdate =
        timeline.getWindowCount()
            - (nextHolder.firstWindowIndexInChild - mediaSourceHolder.firstWindowIndexInChild);
    if (windowOffsetUpdate != 0) {
      correctOffsets(
          mediaSourceHolder.childIndex + 1, /* childIndexUpdate= */ 0, windowOffsetUpdate);
    }
  }
  scheduleTimelineUpdate();
}
 
Example 3
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 4
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 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 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 7
Source File: PlaybackControlView.java    From K-Sonic with MIT License 6 votes vote down vote up
private void updateNavigation() {
  if (!isVisible() || !isAttachedToWindow) {
    return;
  }
  Timeline currentTimeline = player != null ? player.getCurrentTimeline() : null;
  boolean haveNonEmptyTimeline = currentTimeline != null && !currentTimeline.isEmpty();
  boolean isSeekable = false;
  boolean enablePrevious = false;
  boolean enableNext = false;
  if (haveNonEmptyTimeline) {
    int currentWindowIndex = player.getCurrentWindowIndex();
    currentTimeline.getWindow(currentWindowIndex, currentWindow);
    isSeekable = currentWindow.isSeekable;
    enablePrevious = currentWindowIndex > 0 || isSeekable || !currentWindow.isDynamic;
    enableNext = (currentWindowIndex < currentTimeline.getWindowCount() - 1)
        || currentWindow.isDynamic;
  }
  setButtonEnabled(enablePrevious , previousButton);
  setButtonEnabled(enableNext, nextButton);
  setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton);
  setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton);
  if (progressBar != null) {
    progressBar.setEnabled(isSeekable);
  }
}
 
Example 8
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 9
Source File: ExoVideoPlaybackControlView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the specified {@code timeline} can be shown on a multi-window time bar.
 *
 * @param timeline The {@link Timeline} to check.
 * @param window   A scratch {@link Timeline.Window} instance.
 * @return Whether the specified timeline can be shown on a multi-window time bar.
 */
private static boolean canShowMultiWindowTimeBar(Timeline timeline, Timeline.Window window) {
    if (timeline.getWindowCount() > MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR) {
        return false;
    }
    int windowCount = timeline.getWindowCount();
    for (int i = 0; i < windowCount; i++) {
        if (timeline.getWindow(i, window).durationUs == C.TIME_UNSET) {
            return false;
        }
    }
    return true;
}
 
Example 10
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 11
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 12
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 13
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 14
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Returns a new {@link EventTime} for the specified window index and media period id. */
protected EventTime generateEventTime(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
  Assertions.checkNotNull(player);
  long realtimeMs = clock.elapsedRealtime();
  Timeline timeline = player.getCurrentTimeline();
  long eventPositionMs;
  if (windowIndex == player.getCurrentWindowIndex()) {
    if (mediaPeriodId != null && mediaPeriodId.isAd()) {
      // This event is for an ad in the currently playing window.
      eventPositionMs =
          player.getCurrentAdGroupIndex() == mediaPeriodId.adGroupIndex
                  && player.getCurrentAdIndexInAdGroup() == mediaPeriodId.adIndexInAdGroup
              ? player.getCurrentPosition()
              : 0 /* Assume start position of 0 for a future ad. */;
    } else {
      // This event is for content in the currently playing window.
      eventPositionMs = player.getContentPosition();
    }
  } else if (windowIndex >= timeline.getWindowCount()
      || (mediaPeriodId != null && mediaPeriodId.isAd())) {
    // This event is for an unknown future window or for an ad in a future window.
    // Assume start position of zero.
    eventPositionMs = 0;
  } else {
    // This event is for content in a future window. Assume default start position.
    eventPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs();
  }
  return new EventTime(
      realtimeMs,
      timeline,
      windowIndex,
      mediaPeriodId,
      eventPositionMs,
      player.getCurrentPosition(),
      player.getTotalBufferedDuration());
}
 
Example 15
Source File: AnalyticsCollector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private EventTime generateMediaPeriodEventTime(
    int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
  Assertions.checkNotNull(player);
  if (mediaPeriodId != null) {
    MediaPeriodInfo mediaPeriodInfo = mediaPeriodQueueTracker.getMediaPeriodInfo(mediaPeriodId);
    return mediaPeriodInfo != null
        ? generateEventTime(mediaPeriodInfo)
        : generateEventTime(Timeline.EMPTY, windowIndex, mediaPeriodId);
  }
  Timeline timeline = player.getCurrentTimeline();
  boolean windowIsInTimeline = windowIndex < timeline.getWindowCount();
  return generateEventTime(
      windowIsInTimeline ? timeline : Timeline.EMPTY, windowIndex, /* mediaPeriodId= */ null);
}
 
Example 16
Source File: PlaybackControlView.java    From K-Sonic with MIT License 5 votes vote down vote up
private void next() {
  Timeline currentTimeline = player.getCurrentTimeline();
  if (currentTimeline.isEmpty()) {
    return;
  }
  int currentWindowIndex = player.getCurrentWindowIndex();
  if (currentWindowIndex < currentTimeline.getWindowCount() - 1) {
    seekTo(currentWindowIndex + 1, C.TIME_UNSET);
  } else if (currentTimeline.getWindow(currentWindowIndex, currentWindow, false).isDynamic) {
    seekTo(currentWindowIndex, C.TIME_UNSET);
  }
}
 
Example 17
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Returns a new {@link EventTime} for the specified window index and media period id. */
protected EventTime generateEventTime(int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
  Assertions.checkNotNull(player);
  long realtimeMs = clock.elapsedRealtime();
  Timeline timeline = player.getCurrentTimeline();
  long eventPositionMs;
  if (windowIndex == player.getCurrentWindowIndex()) {
    if (mediaPeriodId != null && mediaPeriodId.isAd()) {
      // This event is for an ad in the currently playing window.
      eventPositionMs =
          player.getCurrentAdGroupIndex() == mediaPeriodId.adGroupIndex
                  && player.getCurrentAdIndexInAdGroup() == mediaPeriodId.adIndexInAdGroup
              ? player.getCurrentPosition()
              : 0 /* Assume start position of 0 for a future ad. */;
    } else {
      // This event is for content in the currently playing window.
      eventPositionMs = player.getContentPosition();
    }
  } else if (windowIndex >= timeline.getWindowCount()
      || (mediaPeriodId != null && mediaPeriodId.isAd())) {
    // This event is for an unknown future window or for an ad in a future window.
    // Assume start position of zero.
    eventPositionMs = 0;
  } else {
    // This event is for content in a future window. Assume default start position.
    eventPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs();
  }
  return new EventTime(
      realtimeMs,
      timeline,
      windowIndex,
      mediaPeriodId,
      eventPositionMs,
      player.getCurrentPosition(),
      player.getTotalBufferedDuration());
}
 
Example 18
Source File: CustomPlayBackController.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
private void next() {
    Timeline currentTimeline = player.getCurrentTimeline();
    if (currentTimeline == null) {
        return;
    }
    int currentWindowIndex = player.getCurrentWindowIndex();
    if (currentWindowIndex < currentTimeline.getWindowCount() - 1) {
        player.seekToDefaultPosition(currentWindowIndex + 1);
    } else if (currentTimeline.getWindow(currentWindowIndex, window, false).isDynamic) {
        player.seekToDefaultPosition();
    }
}
 
Example 19
Source File: AnalyticsCollector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private EventTime generateEventTime(@Nullable MediaPeriodInfo mediaPeriodInfo) {
  Assertions.checkNotNull(player);
  if (mediaPeriodInfo == null) {
    int windowIndex = player.getCurrentWindowIndex();
    mediaPeriodInfo = mediaPeriodQueueTracker.tryResolveWindowIndex(windowIndex);
    if (mediaPeriodInfo == null) {
      Timeline timeline = player.getCurrentTimeline();
      boolean windowIsInTimeline = windowIndex < timeline.getWindowCount();
      return generateEventTime(
          windowIsInTimeline ? timeline : Timeline.EMPTY, windowIndex, /* mediaPeriodId= */ null);
    }
  }
  return generateEventTime(
      mediaPeriodInfo.timeline, mediaPeriodInfo.windowIndex, mediaPeriodInfo.mediaPeriodId);
}
 
Example 20
Source File: AnalyticsCollector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private EventTime generateMediaPeriodEventTime(
    int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
  Assertions.checkNotNull(player);
  if (mediaPeriodId != null) {
    MediaPeriodInfo mediaPeriodInfo = mediaPeriodQueueTracker.getMediaPeriodInfo(mediaPeriodId);
    return mediaPeriodInfo != null
        ? generateEventTime(mediaPeriodInfo)
        : generateEventTime(Timeline.EMPTY, windowIndex, mediaPeriodId);
  }
  Timeline timeline = player.getCurrentTimeline();
  boolean windowIsInTimeline = windowIndex < timeline.getWindowCount();
  return generateEventTime(
      windowIsInTimeline ? timeline : Timeline.EMPTY, windowIndex, /* mediaPeriodId= */ null);
}