FakeMultiPeriodLiveTimeline


@UnstableApi
class FakeMultiPeriodLiveTimeline : 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

const Long
const Long

Public constructors

FakeMultiPeriodLiveTimeline(
    availabilityStartTimeMs: Long,
    liveWindowDurationUs: Long,
    nowUs: Long,
    adSequencePattern: BooleanArray!,
    periodDurationMsPattern: LongArray!,
    isContentTimeline: Boolean,
    populateAds: Boolean,
    playedAds: Boolean
)

Creates an instance.

Public functions

Unit
advanceNowUs(durationUs: Long)

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(periodIndex: Int, period: Timeline.Period!, setIds: Boolean)

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

Int

Returns the number of periods in the timeline.

Long
getPeriodStartTimeUs(periodIndex: Int)

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

Any!
getUidOfPeriod(periodIndex: Int)

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

Timeline.Window!
getWindow(
    windowIndex: Int,
    window: Timeline.Window!,
    defaultPositionProjectionUs: Long
)

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
const Timeline!

An empty timeline.

Inherited functions

From androidx.media3.common.Timeline
Timeline!

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

Boolean
equals(obj: Any?)
java-static Timeline!

Restores a Timeline from a Bundle.

Int
getFirstWindowIndex(shuffleModeEnabled: Boolean)

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

Int
getLastWindowIndex(shuffleModeEnabled: Boolean)

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

Int
getNextPeriodIndex(
    periodIndex: Int,
    period: Timeline.Period!,
    window: Timeline.Window!,
    @Player.RepeatMode repeatMode: Int,
    shuffleModeEnabled: Boolean
)

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

Int
getNextWindowIndex(
    windowIndex: Int,
    @Player.RepeatMode repeatMode: Int,
    shuffleModeEnabled: Boolean
)

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

Timeline.Period!
getPeriod(periodIndex: Int, period: Timeline.Period!)

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

Timeline.Period!
getPeriodByUid(periodUid: Any!, period: Timeline.Period!)

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

Pair<Any!, Long!>!
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(window, period, windowIndex, windowPositionUs)")
getPeriodPosition(
    window: Timeline.Window!,
    period: Timeline.Period!,
    windowIndex: Int,
    windowPositionUs: Long
)

This function is deprecated.

Use getPeriodPositionUs instead.

Pair<Any!, Long!>?
@UnstableApi
@InlineMe(replacement = "this.getPeriodPositionUs(" + "window, period, windowIndex, windowPositionUs, defaultPositionProjectionUs)")
getPeriodPosition(
    window: Timeline.Window!,
    period: Timeline.Period!,
    windowIndex: Int,
    windowPositionUs: Long,
    defaultPositionProjectionUs: Long
)

This function is deprecated.

Use getPeriodPositionUs instead.

Pair<Any!, Long!>!
getPeriodPositionUs(
    window: Timeline.Window!,
    period: Timeline.Period!,
    windowIndex: Int,
    windowPositionUs: Long
)

Calls getPeriodPositionUs with a zero default position projection.

Pair<Any!, Long!>?
getPeriodPositionUs(
    window: Timeline.Window!,
    period: Timeline.Period!,
    windowIndex: Int,
    windowPositionUs: Long,
    defaultPositionProjectionUs: Long
)

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

Int
getPreviousWindowIndex(
    windowIndex: Int,
    @Player.RepeatMode repeatMode: Int,
    shuffleModeEnabled: Boolean
)

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

Timeline.Window!
getWindow(windowIndex: Int, window: Timeline.Window!)

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

Int
Boolean

Returns whether the timeline is empty.

Boolean
isLastPeriod(
    periodIndex: Int,
    period: Timeline.Period!,
    window: Timeline.Window!,
    @Player.RepeatMode repeatMode: Int,
    shuffleModeEnabled: Boolean
)

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

Bundle!

Returns a Bundle representing the information stored in this object.

Constants

AD_PERIOD_DURATION_MS

const val AD_PERIOD_DURATION_MS = 10000: Long

PERIOD_DURATION_MS

const val PERIOD_DURATION_MS = 30000: Long

Public constructors

FakeMultiPeriodLiveTimeline

FakeMultiPeriodLiveTimeline(
    availabilityStartTimeMs: Long,
    liveWindowDurationUs: Long,
    nowUs: Long,
    adSequencePattern: BooleanArray!,
    periodDurationMsPattern: LongArray!,
    isContentTimeline: Boolean,
    populateAds: Boolean,
    playedAds: Boolean
)

Creates an instance.

Parameters
availabilityStartTimeMs: Long

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

liveWindowDurationUs: Long

The duration of the live window.

nowUs: Long

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

adSequencePattern: BooleanArray!

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

periodDurationMsPattern: LongArray!

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

isContentTimeline: Boolean

Whether the timeline is a content timeline without s.

populateAds: Boolean

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

playedAds: Boolean

Whether ads should be marked as played if populated.

Public functions

advanceNowUs

fun advanceNowUs(durationUs: Long): Unit

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

getIndexOfPeriod

fun getIndexOfPeriod(uid: Any!): Int

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

Parameters
uid: Any!

A unique identifier for a period.

Returns
Int

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

getPeriod

fun getPeriod(periodIndex: Int, period: Timeline.Period!, setIds: Boolean): Timeline.Period!

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

Parameters
periodIndex: Int

The index of the period.

period: Timeline.Period!

The Period to populate. Must not be null.

setIds: Boolean

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

fun getPeriodCount(): Int

Returns the number of periods in the timeline.

getPeriodStartTimeUs

fun getPeriodStartTimeUs(periodIndex: Int): Long

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

fun getUidOfPeriod(periodIndex: Int): Any!

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

Parameters
periodIndex: Int

The index of the period.

Returns
Any!

The unique id of the period.

getWindow

fun getWindow(
    windowIndex: Int,
    window: Timeline.Window!,
    defaultPositionProjectionUs: Long
): Timeline.Window!

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

Parameters
windowIndex: Int

The index of the window.

window: Timeline.Window!

The Window to populate. Must not be null.

defaultPositionProjectionUs: Long

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

fun getWindowCount(): Int

Returns the number of windows in the timeline.

getWindowStartTimeUs

fun getWindowStartTimeUs(): Long

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