@UnstableApi
public final class FakeTimeline extends Timeline


Fake Timeline which can be setup to return custom TimelineWindowDefinitions.

Summary

Nested types

Definition used to define a FakeTimeline.

Constants

static final MediaItem

The fake media item used by the fake timeline.

Public constructors

Create a fake timeline with one seekable, non-dynamic window with one period and a duration of DEFAULT_WINDOW_DURATION_US.

FakeTimeline(
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions.

FakeTimeline(
    Object[] manifests,
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions.

FakeTimeline(int windowCount, Object[] manifests)

Creates a fake timeline with the given number of seekable, non-dynamic windows with one period with a duration of DEFAULT_WINDOW_DURATION_US each.

FakeTimeline(
    Object[] manifests,
    ShuffleOrder shuffleOrder,
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions and .

Public methods

static AdPlaybackState
createAdPlaybackState(int adsPerAdGroup, long[] adGroupTimesUs)

Returns an ad playback state with the specified number of ads in each of the specified ad groups, each ten seconds long.

static FakeTimeline
createMultiPeriodAdTimeline(
    Object windowId,
    int numberOfPlayedAds,
    boolean[] isAdPeriodFlags
)

Creates a multi-period timeline with ad and content periods specified by the flags passed as var-arg arguments.

ImmutableMap<ObjectAdPlaybackState>
getAdPlaybackStates(int windowIndex)

Returns a map of ad playback states keyed by the period UID.

int
getFirstWindowIndex(boolean shuffleModeEnabled)

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

int

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

int
getLastWindowIndex(boolean shuffleModeEnabled)

Returns the index of the last window in the playback order depending on 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.

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.

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.

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.

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.

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.

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).

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

FAKE_MEDIA_ITEM

public static final MediaItem FAKE_MEDIA_ITEM

The fake media item used by the fake timeline.

Public constructors

FakeTimeline

public FakeTimeline()

Create a fake timeline with one seekable, non-dynamic window with one period and a duration of DEFAULT_WINDOW_DURATION_US.

FakeTimeline

public FakeTimeline(
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions.

Parameters
FakeTimeline.TimelineWindowDefinition[] windowDefinitions

A list of TimelineWindowDefinitions.

FakeTimeline

public FakeTimeline(
    Object[] manifests,
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions.

Parameters
Object[] manifests

The manifests of the windows.

FakeTimeline.TimelineWindowDefinition[] windowDefinitions

A list of TimelineWindowDefinitions.

FakeTimeline

public FakeTimeline(int windowCount, Object[] manifests)

Creates a fake timeline with the given number of seekable, non-dynamic windows with one period with a duration of DEFAULT_WINDOW_DURATION_US each.

Parameters
int windowCount

The number of windows.

Object[] manifests

The manifests of the windows.

FakeTimeline

public FakeTimeline(
    Object[] manifests,
    ShuffleOrder shuffleOrder,
    FakeTimeline.TimelineWindowDefinition[] windowDefinitions
)

Creates a fake timeline with the given window definitions and .

Parameters
Object[] manifests

The manifests of the windows.

ShuffleOrder shuffleOrder

A shuffle ordering for the windows.

FakeTimeline.TimelineWindowDefinition[] windowDefinitions

A list of TimelineWindowDefinitions.

Public methods

createAdPlaybackState

public static AdPlaybackState createAdPlaybackState(int adsPerAdGroup, long[] adGroupTimesUs)

Returns an ad playback state with the specified number of ads in each of the specified ad groups, each ten seconds long.

Parameters
int adsPerAdGroup

The number of ads per ad group.

long[] adGroupTimesUs

The times of ad groups, in microseconds.

Returns
AdPlaybackState

The ad playback state.

createMultiPeriodAdTimeline

public static FakeTimeline createMultiPeriodAdTimeline(
    Object windowId,
    int numberOfPlayedAds,
    boolean[] isAdPeriodFlags
)

Creates a multi-period timeline with ad and content periods specified by the flags passed as var-arg arguments.

Period uid end up being a new Pair<>(windowId, periodIndex).

Parameters
Object windowId

The window ID.

int numberOfPlayedAds

The number of ads that should be marked as played.

boolean[] isAdPeriodFlags

A value of true indicates an ad period. A value of false indicated a content period.

Returns
FakeTimeline

A timeline with a single window with as many periods as var-arg arguments.

getAdPlaybackStates

public ImmutableMap<ObjectAdPlaybackStategetAdPlaybackStates(int windowIndex)

Returns a map of ad playback states keyed by the period UID.

Parameters
int windowIndex

The window index of the window to get the map of ad playback states from.

getFirstWindowIndex

public int getFirstWindowIndex(boolean shuffleModeEnabled)

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

Parameters
boolean shuffleModeEnabled

Whether shuffling is enabled.

Returns
int

The index of the first window in the playback order, or INDEX_UNSET if the timeline is empty.

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.

getLastWindowIndex

public int getLastWindowIndex(boolean shuffleModeEnabled)

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

Parameters
boolean shuffleModeEnabled

Whether shuffling is enabled.

Returns
int

The index of the last window in the playback order, or INDEX_UNSET if the timeline is empty.

getNextWindowIndex

public 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.

Parameters
int windowIndex

Index of a window in the timeline.

@Player.RepeatMode int repeatMode

A repeat mode.

boolean shuffleModeEnabled

Whether shuffling is enabled.

Returns
int

The index of the next window, or INDEX_UNSET if this is the last window.

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.

getPreviousWindowIndex

public 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.

Parameters
int windowIndex

Index of a window in the timeline.

@Player.RepeatMode int repeatMode

A repeat mode.

boolean shuffleModeEnabled

Whether shuffling is enabled.

Returns
int

The index of the previous window, or INDEX_UNSET if this is the first window.

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.