Class ServerSideInsertedAdsUtil
- java.lang.Object
-
- com.google.android.exoplayer2.source.ads.ServerSideInsertedAdsUtil
-
public final class ServerSideInsertedAdsUtil extends Object
A static utility class with methods to work with server-side inserted ads.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AdPlaybackStateaddAdGroupToAdPlaybackState(AdPlaybackState adPlaybackState, long fromPositionUs, long toPositionUs, long contentResumeOffsetUs)Adds a new server-side inserted ad group to anAdPlaybackState.static intgetAdCountInGroup(AdPlaybackState adPlaybackState, int adGroupIndex)Returns the number of ads in an ad group, treating an unknown number as zero ads.static longgetMediaPeriodPositionUs(long positionUs, MediaPeriodId mediaPeriodId, AdPlaybackState adPlaybackState)Returns the position in aMediaPeriodfor a position in the underlying server-side inserted ads stream.static longgetMediaPeriodPositionUsForAd(long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState)Returns the position in an adMediaPeriodfor a position in the underlying server-side inserted ads stream.static longgetMediaPeriodPositionUsForContent(long positionUs, int nextAdGroupIndex, AdPlaybackState adPlaybackState)Returns the position in a contentMediaPeriodfor a position in the underlying server-side inserted ads stream.static longgetStreamDurationUs(Player player, AdPlaybackState adPlaybackState)Returns the duration of the underlying server-side inserted ads stream for the currentTimeline.Periodin thePlayer.static longgetStreamPositionUs(long positionUs, MediaPeriodId mediaPeriodId, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in aMediaPeriod.static longgetStreamPositionUs(Player player, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for the current playback position in thePlayer.static longgetStreamPositionUsForAd(long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in an adMediaPeriod.static longgetStreamPositionUsForContent(long positionUs, int nextAdGroupIndex, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in a contentMediaPeriod.
-
-
-
Method Detail
-
addAdGroupToAdPlaybackState
@CheckResult public static AdPlaybackState addAdGroupToAdPlaybackState(AdPlaybackState adPlaybackState, long fromPositionUs, long toPositionUs, long contentResumeOffsetUs)
Adds a new server-side inserted ad group to anAdPlaybackState.- Parameters:
adPlaybackState- The existingAdPlaybackState.fromPositionUs- The position in the underlying server-side inserted ads stream at which the ad group starts, in microseconds.toPositionUs- The position in the underlying server-side inserted ads stream at which the ad group ends, in microseconds.contentResumeOffsetUs- 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 oftoPositionUs-fromPositionUskeeps the original stream timestamps after the ad group.- Returns:
- The updated
AdPlaybackState.
-
getStreamDurationUs
public static long getStreamDurationUs(Player player, AdPlaybackState adPlaybackState)
Returns the duration of the underlying server-side inserted ads stream for the currentTimeline.Periodin thePlayer.- Parameters:
player- ThePlayer.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The duration of the underlying server-side inserted ads stream, in microseconds, or
C.TIME_UNSETif it can't be determined.
-
getStreamPositionUs
public static long getStreamPositionUs(Player player, AdPlaybackState adPlaybackState)
Returns the position in the underlying server-side inserted ads stream for the current playback position in thePlayer.- Parameters:
player- ThePlayer.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the underlying server-side inserted ads stream, in microseconds, or
C.TIME_UNSETif it can't be determined.
-
getStreamPositionUs
public static long getStreamPositionUs(long positionUs, MediaPeriodId mediaPeriodId, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in aMediaPeriod.- Parameters:
positionUs- The position in theMediaPeriod, in microseconds.mediaPeriodId- TheMediaPeriodIdof theMediaPeriod.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the underlying server-side inserted ads stream, in microseconds.
-
getMediaPeriodPositionUs
public static long getMediaPeriodPositionUs(long positionUs, MediaPeriodId mediaPeriodId, AdPlaybackState adPlaybackState)Returns the position in aMediaPeriodfor a position in the underlying server-side inserted ads stream.- Parameters:
positionUs- The position in the underlying server-side inserted ads stream, in microseconds.mediaPeriodId- TheMediaPeriodIdof theMediaPeriod.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the
MediaPeriod, in microseconds.
-
getStreamPositionUsForAd
public static long getStreamPositionUsForAd(long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in an adMediaPeriod.- Parameters:
positionUs- The position in the adMediaPeriod, in microseconds.adGroupIndex- The ad group index of the ad.adIndexInAdGroup- The index of the ad in the ad group.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the underlying server-side inserted ads stream, in microseconds.
-
getMediaPeriodPositionUsForAd
public static long getMediaPeriodPositionUsForAd(long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState)Returns the position in an adMediaPeriodfor a position in the underlying server-side inserted ads stream.- Parameters:
positionUs- The position in the underlying server-side inserted ads stream, in microseconds.adGroupIndex- The ad group index of the ad.adIndexInAdGroup- The index of the ad in the ad group.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the ad
MediaPeriod, in microseconds.
-
getStreamPositionUsForContent
public static long getStreamPositionUsForContent(long positionUs, int nextAdGroupIndex, AdPlaybackState adPlaybackState)Returns the position in the underlying server-side inserted ads stream for a position in a contentMediaPeriod.- Parameters:
positionUs- The position in the contentMediaPeriod, in microseconds.nextAdGroupIndex- The next ad group index after the content, orC.INDEX_UNSETif there is no following ad group. Ad groups from this index are not used to adjust the position.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the underlying server-side inserted ads stream, in microseconds.
-
getMediaPeriodPositionUsForContent
public static long getMediaPeriodPositionUsForContent(long positionUs, int nextAdGroupIndex, AdPlaybackState adPlaybackState)Returns the position in a contentMediaPeriodfor a position in the underlying server-side inserted ads stream.- Parameters:
positionUs- The position in the underlying server-side inserted ads stream, in microseconds.nextAdGroupIndex- The next ad group index after the content, orC.INDEX_UNSETif there is no following ad group. Ad groups from this index are not used to adjust the position.adPlaybackState- TheAdPlaybackStatedefining the ad groups.- Returns:
- The position in the content
MediaPeriod, in microseconds.
-
getAdCountInGroup
public static int getAdCountInGroup(AdPlaybackState adPlaybackState, int adGroupIndex)
Returns the number of ads in an ad group, treating an unknown number as zero ads.- Parameters:
adPlaybackState- TheAdPlaybackState.adGroupIndex- The index of the ad group.- Returns:
- The number of ads in the ad group.
-
-