ServerSideAdInsertionUtil


@UnstableApi
class ServerSideAdInsertionUtil


A static utility class with methods to work with server-side inserted ads.

Summary

Public functions

java-static AdPlaybackState!
addAdGroupToAdPlaybackState(
    adPlaybackState: AdPlaybackState!,
    fromPositionUs: Long,
    contentResumeOffsetUs: Long,
    adDurationsUs: LongArray!
)

Adds a new server-side inserted ad group to an AdPlaybackState.

java-static Int
getAdCountInGroup(adPlaybackState: AdPlaybackState!, adGroupIndex: Int)

Returns the number of ads in an ad group, treating an unknown number as zero ads.

java-static Long
getMediaPeriodPositionUs(
    positionUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    adPlaybackState: AdPlaybackState!
)

Returns the position in a MediaPeriod for a position in the underlying server-side inserted ads stream.

java-static Long
getMediaPeriodPositionUsForAd(
    positionUs: Long,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    adPlaybackState: AdPlaybackState!
)

Returns the position in an ad MediaPeriod for a position in the underlying server-side inserted ads stream.

java-static Long
getMediaPeriodPositionUsForContent(
    positionUs: Long,
    nextAdGroupIndex: Int,
    adPlaybackState: AdPlaybackState!
)

Returns the position in a content MediaPeriod for a position in the underlying server-side inserted ads stream.

java-static Long
getStreamPositionUs(player: Player!, adPlaybackState: AdPlaybackState!)

Returns the position in the underlying server-side inserted ads stream for the current playback position in the Player.

java-static Long
getStreamPositionUs(
    positionUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    adPlaybackState: AdPlaybackState!
)

Returns the position in the underlying server-side inserted ads stream for a position in a MediaPeriod.

java-static Long
getStreamPositionUsForAd(
    positionUs: Long,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    adPlaybackState: AdPlaybackState!
)

Returns the position in the underlying server-side inserted ads stream for a position in an ad MediaPeriod.

java-static Long
getStreamPositionUsForContent(
    positionUs: Long,
    nextAdGroupIndex: Int,
    adPlaybackState: AdPlaybackState!
)

Returns the position in the underlying server-side inserted ads stream for a position in a content MediaPeriod.

Public functions

addAdGroupToAdPlaybackState

java-static fun addAdGroupToAdPlaybackState(
    adPlaybackState: AdPlaybackState!,
    fromPositionUs: Long,
    contentResumeOffsetUs: Long,
    adDurationsUs: LongArray!
): AdPlaybackState!

Adds a new server-side inserted ad group to an AdPlaybackState.

If the first ad with a non-zero duration is not the first ad in the group, all ads before that ad are marked as skipped.

Parameters
adPlaybackState: AdPlaybackState!

The existing AdPlaybackState.

fromPositionUs: Long

The position in the underlying server-side inserted ads stream at which the ad group starts, in microseconds.

contentResumeOffsetUs: Long

The timestamp offset which should be added to the content stream when resuming playback after the ad group. An offset of 0 collapses the ad group to a single insertion point, an offset of toPositionUs-fromPositionUs keeps the original stream timestamps after the ad group.

adDurationsUs: LongArray!

The durations of the ads to be added to the group, in microseconds.

Returns
AdPlaybackState!

The updated AdPlaybackState.

getAdCountInGroup

java-static fun getAdCountInGroup(adPlaybackState: AdPlaybackState!, adGroupIndex: Int): Int

Returns the number of ads in an ad group, treating an unknown number as zero ads.

Parameters
adPlaybackState: AdPlaybackState!

The AdPlaybackState.

adGroupIndex: Int

The index of the ad group.

Returns
Int

The number of ads in the ad group.

getMediaPeriodPositionUs

java-static fun getMediaPeriodPositionUs(
    positionUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in a MediaPeriod for a position in the underlying server-side inserted ads stream.

Parameters
positionUs: Long

The position in the underlying server-side inserted ads stream, in microseconds.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaPeriodId of the MediaPeriod.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the MediaPeriod, in microseconds.

getMediaPeriodPositionUsForAd

java-static fun getMediaPeriodPositionUsForAd(
    positionUs: Long,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in an ad MediaPeriod for a position in the underlying server-side inserted ads stream.

Parameters
positionUs: Long

The position in the underlying server-side inserted ads stream, in microseconds.

adGroupIndex: Int

The ad group index of the ad.

adIndexInAdGroup: Int

The index of the ad in the ad group.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the ad MediaPeriod, in microseconds.

getMediaPeriodPositionUsForContent

java-static fun getMediaPeriodPositionUsForContent(
    positionUs: Long,
    nextAdGroupIndex: Int,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in a content MediaPeriod for a position in the underlying server-side inserted ads stream.

Parameters
positionUs: Long

The position in the underlying server-side inserted ads stream, in microseconds.

nextAdGroupIndex: Int

The next ad group index after the content, or INDEX_UNSET if there is no following ad group. Ad groups from this index are not used to adjust the position.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the content MediaPeriod, in microseconds.

getStreamPositionUs

java-static fun getStreamPositionUs(player: Player!, adPlaybackState: AdPlaybackState!): Long

Returns the position in the underlying server-side inserted ads stream for the current playback position in the Player.

Parameters
player: Player!

The Player.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the underlying server-side inserted ads stream, in microseconds, or TIME_UNSET if it can't be determined.

getStreamPositionUs

java-static fun getStreamPositionUs(
    positionUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in the underlying server-side inserted ads stream for a position in a MediaPeriod.

Parameters
positionUs: Long

The position in the MediaPeriod, in microseconds.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaPeriodId of the MediaPeriod.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the underlying server-side inserted ads stream, in microseconds.

getStreamPositionUsForAd

java-static fun getStreamPositionUsForAd(
    positionUs: Long,
    adGroupIndex: Int,
    adIndexInAdGroup: Int,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in the underlying server-side inserted ads stream for a position in an ad MediaPeriod.

Parameters
positionUs: Long

The position in the ad MediaPeriod, in microseconds.

adGroupIndex: Int

The ad group index of the ad.

adIndexInAdGroup: Int

The index of the ad in the ad group.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the underlying server-side inserted ads stream, in microseconds.

getStreamPositionUsForContent

java-static fun getStreamPositionUsForContent(
    positionUs: Long,
    nextAdGroupIndex: Int,
    adPlaybackState: AdPlaybackState!
): Long

Returns the position in the underlying server-side inserted ads stream for a position in a content MediaPeriod.

Parameters
positionUs: Long

The position in the content MediaPeriod, in microseconds.

nextAdGroupIndex: Int

The next ad group index after the content, or INDEX_UNSET if there is no following ad group. Ad groups from this index are not used to adjust the position.

adPlaybackState: AdPlaybackState!

The AdPlaybackState defining the ad groups.

Returns
Long

The position in the underlying server-side inserted ads stream, in microseconds.