FakeMultiPeriodLiveTimeline


@UnstableApi
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 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.

Summary

Constants

static final long
static final long

Public constructors

FakeMultiPeriodLiveTimeline(
    long availabilityStartTimeMs,
    long liveWindowDurationUs,
    long nowUs,
    boolean[] adSequencePattern,
    long[] periodDurationMsPattern,
    boolean isContentTimeline,
    boolean populateAds,
    boolean playedAds
)

Creates an instance.

Public methods

void
advanceNowUs(long durationUs)

Advances the live window by the given duration, in microseconds.

int

Returns the index of the period identified by its unique uid, or INDEX_UNSET if the period is not in the timeline.

Timeline.Period
getPeriod(int periodIndex, Timeline.Period period, boolean setIds)

Populates a Period with data for the period at the specified index.

int

Returns the number of periods in the timeline.

long
getPeriodStartTimeUs(int periodIndex)

Returns the period start time since Unix epoch, in microseconds.

Object
getUidOfPeriod(int periodIndex)

Returns the unique id of the period identified by its index in the timeline.

Timeline.Window
getWindow(
    int windowIndex,
    Timeline.Window window,
    long defaultPositionProjectionUs
)

Populates a Window with data for the window at the specified index.

int

Returns the number of windows in the timeline.

long

The window's start time in microseconds since the Unix epoch, or TIME_UNSET if unknown or not applicable.

Inherited Constants

From androidx.media3.common.Timeline
static final Timeline

An empty timeline.

Inherited methods

From androidx.media3.common.Timeline
final Timeline

Returns a copy of this timeline containing just the single specified Window.

boolean
static Timeline

Restores a Timeline from a Bundle.

int
getFirstWindowIndex(boolean shuffleModeEnabled)

Returns the index of the first window in the playback order depending on whether shuffling is enabled.

int
getLastWindowIndex(boolean shuffleModeEnabled)

Returns the index of the last window in the playback order depending on whether shuffling is enabled.

final int
getNextPeriodIndex(
    int periodIndex,
    Timeline.Period period,
    Timeline.Window window,
    @Player.RepeatMode int repeatMode,
    boolean shuffleModeEnabled
)

Returns the index of the period after the period at index periodIndex depending on the repeatMode and whether shuffling is enabled.

int
getNextWindowIndex(
    int windowIndex,
    @Player.RepeatMode int repeatMode,
    boolean shuffleModeEnabled
)

Returns the index of the window after the window at index windowIndex depending on the repeatMode and whether shuffling is enabled.

final Timeline.Period
getPeriod(int periodIndex, Timeline.Period period)

Populates a Period with data for the period at the specified index.

Timeline.Period
getPeriodByUid(Object periodUid, Timeline.Period period)

Populates a Period with data for the period with the specified unique identifier.

final Pair<ObjectLong>
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(window, period, windowIndex, windowPositionUs)")
getPeriodPosition(
    Timeline.Window window,
    Timeline.Period period,
    int windowIndex,
    long windowPositionUs
)

This method is deprecated.

Use getPeriodPositionUs instead.

final @Nullable Pair<ObjectLong>
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(" + "window, period, windowIndex, windowPositionUs, defaultPositionProjectionUs)")
getPeriodPosition(
    Timeline.Window window,
    Timeline.Period period,
    int windowIndex,
    long windowPositionUs,
    long defaultPositionProjectionUs
)

This method is deprecated.

Use getPeriodPositionUs instead.

final Pair<ObjectLong>
getPeriodPositionUs(
    Timeline.Window window,
    Timeline.Period period,
    int windowIndex,
    long windowPositionUs
)

Calls getPeriodPositionUs with a zero default position projection.

final @Nullable Pair<ObjectLong>
getPeriodPositionUs(
    Timeline.Window window,
    Timeline.Period period,
    int windowIndex,
    long windowPositionUs,
    long defaultPositionProjectionUs
)

Converts (windowIndex, windowPositionUs) to the corresponding (periodUid, periodPositionUs).

int
getPreviousWindowIndex(
    int windowIndex,
    @Player.RepeatMode int repeatMode,
    boolean shuffleModeEnabled
)

Returns the index of the window before the window at index windowIndex depending on the repeatMode and whether shuffling is enabled.

final Timeline.Window
getWindow(int windowIndex, Timeline.Window window)

Populates a Window with data for the window at the specified index.

int
final boolean

Returns whether the timeline is empty.

final boolean
isLastPeriod(
    int periodIndex,
    Timeline.Period period,
    Timeline.Window window,
    @Player.RepeatMode int repeatMode,
    boolean shuffleModeEnabled
)

Returns whether the given period is the last period of the timeline depending on the repeatMode and whether shuffling is enabled.

final Bundle

Returns a Bundle representing the information stored in this object.

Constants

AD_PERIOD_DURATION_MS

public static final long AD_PERIOD_DURATION_MS = 10000

PERIOD_DURATION_MS

public static final long PERIOD_DURATION_MS = 30000

Public constructors

FakeMultiPeriodLiveTimeline

public FakeMultiPeriodLiveTimeline(
    long availabilityStartTimeMs,
    long liveWindowDurationUs,
    long nowUs,
    boolean[] adSequencePattern,
    long[] periodDurationMsPattern,
    boolean isContentTimeline,
    boolean populateAds,
    boolean playedAds
)

Creates an instance.

Parameters
long availabilityStartTimeMs

The start time of the available time range, UNIX epoch in milliseconds.

long liveWindowDurationUs

The duration of the live window.

long nowUs

The current time that determines the end of the live window.

boolean[] adSequencePattern

The repeating pattern of periods starting at availabilityStartTimeMs. True is an ad period, and false a content period.

long[] periodDurationMsPattern

The repeating pattern of periods durations starting at availabilityStartTimeMs, in milliseconds. Must have the same length as adSequencePattern.

boolean isContentTimeline

Whether the timeline is a content timeline without s.

boolean populateAds

Whether to populate ads in the same way if an ad event has been received.

boolean playedAds

Whether ads should be marked as played if populated.

Public methods

advanceNowUs

public void advanceNowUs(long durationUs)

Advances the live window by the given duration, in microseconds.

getIndexOfPeriod

public int getIndexOfPeriod(Object uid)

Returns the index of the period identified by its unique uid, or INDEX_UNSET if the period is not in the timeline.

Parameters
Object uid

A unique identifier for a period.

Returns
int

The index of the period, or INDEX_UNSET if the period was not found.

getPeriod

public Timeline.Period getPeriod(int periodIndex, Timeline.Period period, boolean setIds)

Populates a Period with data for the period at the specified index.

Parameters
int periodIndex

The index of the period.

Timeline.Period period

The Period to populate. Must not be null.

boolean setIds

Whether id and uid should be populated. If false, the fields will be set to null. The caller should pass false for efficiency reasons unless the fields are required.

Returns
Timeline.Period

The populated Period, for convenience.

getPeriodCount

public int getPeriodCount()

Returns the number of periods in the timeline.

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.

getUidOfPeriod

public Object getUidOfPeriod(int periodIndex)

Returns the unique id of the period identified by its index in the timeline.

Parameters
int periodIndex

The index of the period.

Returns
Object

The unique id of the period.

getWindow

public Timeline.Window getWindow(
    int windowIndex,
    Timeline.Window window,
    long defaultPositionProjectionUs
)

Populates a Window with data for the window at the specified index.

Parameters
int windowIndex

The index of the window.

Timeline.Window window

The Window to populate. Must not be null.

long defaultPositionProjectionUs

A duration into the future that the populated window's default start position should be projected.

Returns
Timeline.Window

The populated Window, for convenience.

getWindowCount

public int getWindowCount()

Returns the number of windows in the timeline.

getWindowStartTimeUs

public long getWindowStartTimeUs()

The window's start time in microseconds since the Unix epoch, or TIME_UNSET if unknown or not applicable.