com.google.android.exoplayer2.Timeline.Window Java Examples

The following examples show how to use com.google.android.exoplayer2.Timeline.Window. 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: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
  return window.set(
      Window.SINGLE_WINDOW_UID,
      tag,
      /* manifest= */ null,
      /* presentationStartTimeMs= */ C.TIME_UNSET,
      /* windowStartTimeMs= */ C.TIME_UNSET,
      /* isSeekable= */ false,
      // Dynamic window to indicate pending timeline updates.
      /* isDynamic= */ true,
      /* isLive= */ false,
      /* defaultPositionUs= */ 0,
      /* durationUs= */ C.TIME_UNSET,
      /* firstPeriodIndex= */ 0,
      /* lastPeriodIndex= */ 0,
      /* positionInFirstPeriodUs= */ 0);
}
 
Example #2
Source File: AnalyticsCollector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an analytics collector.
 *
 * @param clock A {@link Clock} used to generate timestamps.
 */
public AnalyticsCollector(Clock clock) {
  this.clock = Assertions.checkNotNull(clock);
  listeners = new CopyOnWriteArraySet<>();
  mediaPeriodQueueTracker = new MediaPeriodQueueTracker();
  window = new Window();
}
 
Example #3
Source File: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
  timeline.getWindow(windowIndex, window, defaultPositionProjectionUs);
  if (Util.areEqual(window.uid, replacedInternalWindowUid)) {
    window.uid = Window.SINGLE_WINDOW_UID;
  }
  return window;
}
 
Example #4
Source File: AnalyticsCollector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an analytics collector for the specified player.
 *
 * @param player The {@link Player} for which data will be collected. Can be null, if the player
 *     is set by calling {@link AnalyticsCollector#setPlayer(Player)} before using the analytics
 *     collector.
 * @param clock A {@link Clock} used to generate timestamps.
 */
protected AnalyticsCollector(@Nullable Player player, Clock clock) {
  if (player != null) {
    this.player = player;
  }
  this.clock = Assertions.checkNotNull(clock);
  listeners = new CopyOnWriteArraySet<>();
  mediaPeriodQueueTracker = new MediaPeriodQueueTracker();
  window = new Window();
}
 
Example #5
Source File: AnalyticsCollector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an analytics collector for the specified player.
 *
 * @param player The {@link Player} for which data will be collected. Can be null, if the player
 *     is set by calling {@link AnalyticsCollector#setPlayer(Player)} before using the analytics
 *     collector.
 * @param clock A {@link Clock} used to generate timestamps.
 */
protected AnalyticsCollector(@Nullable Player player, Clock clock) {
  if (player != null) {
    this.player = player;
  }
  this.clock = Assertions.checkNotNull(clock);
  listeners = new CopyOnWriteArraySet<>();
  mediaPeriodQueueTracker = new MediaPeriodQueueTracker();
  window = new Window();
}
 
Example #6
Source File: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void onChildSourceInfoRefreshed(
    Void id, MediaSource mediaSource, Timeline newTimeline) {
  if (isPrepared) {
    timeline = timeline.cloneWithUpdatedTimeline(newTimeline);
  } else if (newTimeline.isEmpty()) {
    timeline =
        MaskingTimeline.createWithRealTimeline(
            newTimeline, Window.SINGLE_WINDOW_UID, MaskingTimeline.DUMMY_EXTERNAL_PERIOD_UID);
  } else {
    // 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.
    newTimeline.getWindow(/* windowIndex= */ 0, window);
    long windowStartPositionUs = window.getDefaultPositionUs();
    if (unpreparedMaskingMediaPeriod != null) {
      long periodPreparePositionUs = unpreparedMaskingMediaPeriod.getPreparePositionUs();
      if (periodPreparePositionUs != 0) {
        windowStartPositionUs = periodPreparePositionUs;
      }
    }
    Object windowUid = window.uid;
    Pair<Object, Long> periodPosition =
        newTimeline.getPeriodPosition(
            window, period, /* windowIndex= */ 0, windowStartPositionUs);
    Object periodUid = periodPosition.first;
    long periodPositionUs = periodPosition.second;
    timeline = MaskingTimeline.createWithRealTimeline(newTimeline, windowUid, periodUid);
    if (unpreparedMaskingMediaPeriod != null) {
      MaskingMediaPeriod maskingPeriod = unpreparedMaskingMediaPeriod;
      maskingPeriod.overridePreparePositionUs(periodPositionUs);
      MediaPeriodId idInSource =
          maskingPeriod.id.copyWithPeriodUid(getInternalPeriodUid(maskingPeriod.id.periodUid));
      maskingPeriod.createPeriod(idInSource);
    }
  }
  isPrepared = true;
  refreshSourceInfo(this.timeline);
}
 
Example #7
Source File: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Creates the masking media source.
 *
 * @param mediaSource A {@link MediaSource}.
 * @param useLazyPreparation Whether the {@code mediaSource} is prepared lazily. If false, all
 *     manifest loads and other initial preparation steps happen immediately. If true, these
 *     initial preparations are triggered only when the player starts buffering the media.
 */
public MaskingMediaSource(MediaSource mediaSource, boolean useLazyPreparation) {
  this.mediaSource = mediaSource;
  this.useLazyPreparation = useLazyPreparation;
  window = new Timeline.Window();
  period = new Timeline.Period();
  timeline = MaskingTimeline.createWithDummyTimeline(mediaSource.getTag());
}
 
Example #8
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates an analytics collector for the specified player.
 *
 * @param player The {@link Player} for which data will be collected. Can be null, if the player
 *     is set by calling {@link AnalyticsCollector#setPlayer(Player)} before using the analytics
 *     collector.
 * @param clock A {@link Clock} used to generate timestamps.
 */
protected AnalyticsCollector(@Nullable Player player, Clock clock) {
  this.player = player;
  this.clock = Assertions.checkNotNull(clock);
  listeners = new CopyOnWriteArraySet<>();
  mediaPeriodQueueTracker = new MediaPeriodQueueTracker();
  window = new Window();
}
 
Example #9
Source File: AnalyticsCollector.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates an analytics collector for the specified player.
 *
 * @param player The {@link Player} for which data will be collected. Can be null, if the player
 *     is set by calling {@link AnalyticsCollector#setPlayer(Player)} before using the analytics
 *     collector.
 * @param clock A {@link Clock} used to generate timestamps.
 */
protected AnalyticsCollector(@Nullable Player player, Clock clock) {
  this.player = player;
  this.clock = Assertions.checkNotNull(clock);
  listeners = new CopyOnWriteArraySet<>();
  mediaPeriodQueueTracker = new MediaPeriodQueueTracker();
  window = new Window();
}
 
Example #10
Source File: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an instance with a dummy timeline using the provided window tag.
 *
 * @param windowTag A window tag.
 */
public static MaskingTimeline createWithDummyTimeline(@Nullable Object windowTag) {
  return new MaskingTimeline(
      new DummyTimeline(windowTag), Window.SINGLE_WINDOW_UID, DUMMY_EXTERNAL_PERIOD_UID);
}