Class FakeMultiPeriodLiveTimeline

  • All Implemented Interfaces:
    Bundleable

    public class FakeMultiPeriodLiveTimeline
    extends Timeline
    A fake Timeline that produces a live window with periods according to the available time range.

    The parameters passed to the constructor define the availability start time, the window size and now. Use advanceNowUs(long) to advance the live window of the timeline accordingly.

    The first available period with ID 0 (zero) starts at availabilityStartTimeUs. The live window starts at now - liveWindowDurationUs with the first period of the window having its ID relative to the first available period.

    Periods are either of type content or ad as defined by the ad sequence pattern. A period is an ad if adSequencePattern[id % adSequencePattern.length] evaluates to true. Ad periods have a duration of AD_PERIOD_DURATION_MS and content periods have a duration of PERIOD_DURATION_MS.

    • Constructor Detail

      • FakeMultiPeriodLiveTimeline

        public FakeMultiPeriodLiveTimeline​(long availabilityStartTimeMs,
                                           long liveWindowDurationUs,
                                           long nowUs,
                                           boolean[] adSequencePattern,
                                           long[] periodDurationMsPattern,
                                           boolean isContentTimeline,
                                           boolean populateAds,
                                           boolean playedAds)
        Creates an instance.
        Parameters:
        availabilityStartTimeMs - The start time of the available time range, UNIX epoch in milliseconds.
        liveWindowDurationUs - The duration of the live window.
        nowUs - The current time that determines the end of the live window.
        adSequencePattern - The repeating pattern of periods starting at availabilityStartTimeMs. True is an ad period, and false a content period.
        periodDurationMsPattern - The repeating pattern of periods durations starting at availabilityStartTimeMs, in milliseconds. Must have the same length as adSequencePattern.
        isContentTimeline - Whether the timeline is a content timeline without AdPlaybackStates.
        populateAds - Whether to populate ads in the same way if an ad event has been received.
        playedAds - Whether ads should be marked as played if populated.
    • Method Detail

      • advanceNowUs

        public void advanceNowUs​(long durationUs)
        Advances the live window by the given duration, in microseconds.
      • getWindowStartTimeUs

        public long getWindowStartTimeUs()
        The window's start time in microseconds since the Unix epoch, or C.TIME_UNSET if unknown or not applicable.
      • getPeriodStartTimeUs

        public long getPeriodStartTimeUs​(int periodIndex)
        Returns the period start time since Unix epoch, in microseconds.

        Note: The returned value has millisecond precision only, so the trailing 3 digits are always zeros.

      • getWindowCount

        public int getWindowCount()
        Description copied from class: Timeline
        Returns the number of windows in the timeline.
        Specified by:
        getWindowCount in class Timeline
      • getWindow

        public Timeline.Window getWindow​(int windowIndex,
                                         Timeline.Window window,
                                         long defaultPositionProjectionUs)
        Description copied from class: Timeline
        Populates a Timeline.Window with data for the window at the specified index.
        Specified by:
        getWindow in class Timeline
        Parameters:
        windowIndex - The index of the window.
        window - The Timeline.Window to populate. Must not be null.
        defaultPositionProjectionUs - A duration into the future that the populated window's default start position should be projected.
        Returns:
        The populated Timeline.Window, for convenience.
      • getPeriodCount

        public int getPeriodCount()
        Description copied from class: Timeline
        Returns the number of periods in the timeline.
        Specified by:
        getPeriodCount in class Timeline
      • getIndexOfPeriod

        public int getIndexOfPeriod​(Object uid)
        Description copied from class: Timeline
        Returns the index of the period identified by its unique Timeline.Period.uid, or C.INDEX_UNSET if the period is not in the timeline.
        Specified by:
        getIndexOfPeriod in class Timeline
        Parameters:
        uid - A unique identifier for a period.
        Returns:
        The index of the period, or C.INDEX_UNSET if the period was not found.
      • getUidOfPeriod

        public Object getUidOfPeriod​(int periodIndex)
        Description copied from class: Timeline
        Returns the unique id of the period identified by its index in the timeline.
        Specified by:
        getUidOfPeriod in class Timeline
        Parameters:
        periodIndex - The index of the period.
        Returns:
        The unique id of the period.