Class AdPlaybackState
- java.lang.Object
-
- com.google.android.exoplayer2.source.ads.AdPlaybackState
-
- All Implemented Interfaces:
Bundleable
public final class AdPlaybackState extends Object implements Bundleable
Represents ad group times and information on the state and URIs of ads within each ad group.Instances are immutable. Call the
with*methods to get new instances that have the required changes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAdPlaybackState.AdGroupRepresents a group of ads, with information about their states.static interfaceAdPlaybackState.AdStateRepresents the state of an ad in an ad group.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.Bundleable
Bundleable.Creator<T extends Bundleable>
-
-
Field Summary
Fields Modifier and Type Field Description static intAD_STATE_AVAILABLEState for an ad that has a URL but has not yet been played.static intAD_STATE_ERRORState for an ad that could not be loaded.static intAD_STATE_PLAYEDState for an ad that was played in full.static intAD_STATE_SKIPPEDState for an ad that was skipped.static intAD_STATE_UNAVAILABLEState for an ad that does not yet have a URL.intadGroupCountThe number of ad groups.longadResumePositionUsThe position offset in the first unplayed ad at which to begin playback, in microseconds.ObjectadsIdThe opaque identifier for ads with which this instance is associated, ornullif unset.longcontentDurationUsThe duration of the content period in microseconds, if known.static Bundleable.Creator<AdPlaybackState>CREATORObject that can restoreAdPlaybackStatefrom aBundle.static AdPlaybackStateNONEAd playback state with no ads.intremovedAdGroupCountThe number of ad groups the have been removed.
-
Constructor Summary
Constructors Constructor Description AdPlaybackState(Object adsId, long... adGroupTimesUs)Creates a new ad playback state with the specified ad group times.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)AdPlaybackState.AdGroupgetAdGroup(int adGroupIndex)Returns the specifiedAdPlaybackState.AdGroup.intgetAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs)Returns the index of the next ad group afterpositionUsthat should be played.intgetAdGroupIndexForPositionUs(long positionUs, long periodDurationUs)Returns the index of the ad group at or beforepositionUsthat should be played before the content atpositionUs.inthashCode()booleanisAdInErrorState(int adGroupIndex, int adIndexInAdGroup)Returns whether the specified ad has been marked as inAD_STATE_ERROR.BundletoBundle()Returns aBundlerepresenting the information stored in this object.StringtoString()AdPlaybackStatewithAdCount(int adGroupIndex, int adCount)Returns an instance with the number of ads inadGroupIndexresolved toadCount.AdPlaybackStatewithAdDurationsUs(int adGroupIndex, long... adDurationsUs)Returns an instance with the specified ad durations, in microseconds, in the specified ad group.AdPlaybackStatewithAdDurationsUs(long[][] adDurationUs)Returns an instance with the specified ad durations, in microseconds.AdPlaybackStatewithAdGroupTimeUs(int adGroupIndex, long adGroupTimeUs)Returns an instance with the specified ad group time.AdPlaybackStatewithAdLoadError(int adGroupIndex, int adIndexInAdGroup)Returns an instance with the specified ad marked as having a load error.AdPlaybackStatewithAdResumePositionUs(long adResumePositionUs)Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad.AdPlaybackStatewithAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri)Returns an instance with the specified ad URI.AdPlaybackStatewithContentDurationUs(long contentDurationUs)Returns an instance with the specified content duration, in microseconds.AdPlaybackStatewithContentResumeOffsetUs(int adGroupIndex, long contentResumeOffsetUs)Returns an instance with the specifiedAdPlaybackState.AdGroup.contentResumeOffsetUs, in microseconds, for the specified ad group.AdPlaybackStatewithIsServerSideInserted(int adGroupIndex, boolean isServerSideInserted)Returns an instance with the specified value forAdPlaybackState.AdGroup.isServerSideInsertedin the specified ad group.AdPlaybackStatewithNewAdGroup(int adGroupIndex, long adGroupTimeUs)Returns an instance with a new ad group.AdPlaybackStatewithPlayedAd(int adGroupIndex, int adIndexInAdGroup)Returns an instance with the specified ad marked as played.AdPlaybackStatewithRemovedAdGroupCount(int removedAdGroupCount)Returns an instance with the specified number ofremoved ad groups.AdPlaybackStatewithSkippedAd(int adGroupIndex, int adIndexInAdGroup)Returns an instance with the specified ad marked as skipped.AdPlaybackStatewithSkippedAdGroup(int adGroupIndex)Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state).
-
-
-
Field Detail
-
AD_STATE_UNAVAILABLE
public static final int AD_STATE_UNAVAILABLE
State for an ad that does not yet have a URL.- See Also:
- Constant Field Values
-
AD_STATE_AVAILABLE
public static final int AD_STATE_AVAILABLE
State for an ad that has a URL but has not yet been played.- See Also:
- Constant Field Values
-
AD_STATE_SKIPPED
public static final int AD_STATE_SKIPPED
State for an ad that was skipped.- See Also:
- Constant Field Values
-
AD_STATE_PLAYED
public static final int AD_STATE_PLAYED
State for an ad that was played in full.- See Also:
- Constant Field Values
-
AD_STATE_ERROR
public static final int AD_STATE_ERROR
State for an ad that could not be loaded.- See Also:
- Constant Field Values
-
NONE
public static final AdPlaybackState NONE
Ad playback state with no ads.
-
adsId
@Nullable public final Object adsId
The opaque identifier for ads with which this instance is associated, ornullif unset.
-
adGroupCount
public final int adGroupCount
The number of ad groups.
-
adResumePositionUs
public final long adResumePositionUs
The position offset in the first unplayed ad at which to begin playback, in microseconds.
-
contentDurationUs
public final long contentDurationUs
The duration of the content period in microseconds, if known.C.TIME_UNSETotherwise.
-
removedAdGroupCount
public final int removedAdGroupCount
The number of ad groups the have been removed. Ad groups with indices between0(inclusive) andremovedAdGroupCount(exclusive) will be empty and must not be modified by any of thewith*methods.
-
CREATOR
public static final Bundleable.Creator<AdPlaybackState> CREATOR
Object that can restoreAdPlaybackStatefrom aBundle.The
adsIdof restored instances will always benull.
-
-
Constructor Detail
-
AdPlaybackState
public AdPlaybackState(Object adsId, long... adGroupTimesUs)
Creates a new ad playback state with the specified ad group times.- Parameters:
adsId- The opaque identifier for ads with which this instance is associated.adGroupTimesUs- The times of ad groups in microseconds, relative to the start of theTimeline.Periodthey belong to. A final element with the valueC.TIME_END_OF_SOURCEindicates that there is a postroll ad.
-
-
Method Detail
-
getAdGroup
public AdPlaybackState.AdGroup getAdGroup(@IntRange(from=0L) int adGroupIndex)
Returns the specifiedAdPlaybackState.AdGroup.
-
getAdGroupIndexForPositionUs
public int getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs)Returns the index of the ad group at or beforepositionUsthat should be played before the content atpositionUs. ReturnsC.INDEX_UNSETif the ad group at or beforepositionUshas no ads remaining to be played, or if there is no such ad group.- Parameters:
positionUs- The period position at or before which to find an ad group, in microseconds, orC.TIME_END_OF_SOURCEfor the end of the stream (in which case the index of any unplayed postroll ad group will be returned).periodDurationUs- The duration of the containing timeline period, in microseconds, orC.TIME_UNSETif not known.- Returns:
- The index of the ad group, or
C.INDEX_UNSET.
-
getAdGroupIndexAfterPositionUs
public int getAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs)Returns the index of the next ad group afterpositionUsthat should be played. ReturnsC.INDEX_UNSETif there is no such ad group.- Parameters:
positionUs- The period position after which to find an ad group, in microseconds, orC.TIME_END_OF_SOURCEfor the end of the stream (in which case there can be no ad group after the position).periodDurationUs- The duration of the containing timeline period, in microseconds, orC.TIME_UNSETif not known.- Returns:
- The index of the ad group, or
C.INDEX_UNSET.
-
isAdInErrorState
public boolean isAdInErrorState(@IntRange(from=0L) int adGroupIndex, @IntRange(from=0L) int adIndexInAdGroup)Returns whether the specified ad has been marked as inAD_STATE_ERROR.
-
withAdGroupTimeUs
@CheckResult public AdPlaybackState withAdGroupTimeUs(@IntRange(from=0L) int adGroupIndex, long adGroupTimeUs)
Returns an instance with the specified ad group time.- Parameters:
adGroupIndex- The index of the ad group.adGroupTimeUs- The new ad group time, in microseconds, orC.TIME_END_OF_SOURCEto indicate a postroll ad.- Returns:
- The updated ad playback state.
-
withNewAdGroup
@CheckResult public AdPlaybackState withNewAdGroup(@IntRange(from=0L) int adGroupIndex, long adGroupTimeUs)
Returns an instance with a new ad group.- Parameters:
adGroupIndex- The insertion index of the new group.adGroupTimeUs- The ad group time, in microseconds, orC.TIME_END_OF_SOURCEto indicate a postroll ad.- Returns:
- The updated ad playback state.
-
withAdCount
@CheckResult public AdPlaybackState withAdCount(@IntRange(from=0L) int adGroupIndex, @IntRange(from=1L) int adCount)
Returns an instance with the number of ads inadGroupIndexresolved toadCount. The ad count must be greater than zero.
-
withAdUri
@CheckResult public AdPlaybackState withAdUri(@IntRange(from=0L) int adGroupIndex, @IntRange(from=0L) int adIndexInAdGroup, Uri uri)
Returns an instance with the specified ad URI.
-
withPlayedAd
@CheckResult public AdPlaybackState withPlayedAd(@IntRange(from=0L) int adGroupIndex, @IntRange(from=0L) int adIndexInAdGroup)
Returns an instance with the specified ad marked as played.
-
withSkippedAd
@CheckResult public AdPlaybackState withSkippedAd(@IntRange(from=0L) int adGroupIndex, @IntRange(from=0L) int adIndexInAdGroup)
Returns an instance with the specified ad marked as skipped.
-
withAdLoadError
@CheckResult public AdPlaybackState withAdLoadError(@IntRange(from=0L) int adGroupIndex, @IntRange(from=0L) int adIndexInAdGroup)
Returns an instance with the specified ad marked as having a load error.
-
withSkippedAdGroup
@CheckResult public AdPlaybackState withSkippedAdGroup(@IntRange(from=0L) int adGroupIndex)
Returns an instance with all ads in the specified ad group skipped (except for those already marked as played or in the error state).
-
withAdDurationsUs
@CheckResult public AdPlaybackState withAdDurationsUs(long[][] adDurationUs)
Returns an instance with the specified ad durations, in microseconds.Must only be used if
removedAdGroupCountis 0.
-
withAdDurationsUs
@CheckResult public AdPlaybackState withAdDurationsUs(@IntRange(from=0L) int adGroupIndex, long... adDurationsUs)
Returns an instance with the specified ad durations, in microseconds, in the specified ad group.
-
withAdResumePositionUs
@CheckResult public AdPlaybackState withAdResumePositionUs(long adResumePositionUs)
Returns an instance with the specified ad resume position, in microseconds, relative to the start of the current ad.
-
withContentDurationUs
@CheckResult public AdPlaybackState withContentDurationUs(long contentDurationUs)
Returns an instance with the specified content duration, in microseconds.
-
withRemovedAdGroupCount
@CheckResult public AdPlaybackState withRemovedAdGroupCount(@IntRange(from=0L) int removedAdGroupCount)
Returns an instance with the specified number ofremoved ad groups.Ad groups with indices between
0(inclusive) andremovedAdGroupCount(exclusive) will be empty and must not be modified by any of thewith*methods.
-
withContentResumeOffsetUs
@CheckResult public AdPlaybackState withContentResumeOffsetUs(@IntRange(from=0L) int adGroupIndex, long contentResumeOffsetUs)
Returns an instance with the specifiedAdPlaybackState.AdGroup.contentResumeOffsetUs, in microseconds, for the specified ad group.
-
withIsServerSideInserted
@CheckResult public AdPlaybackState withIsServerSideInserted(@IntRange(from=0L) int adGroupIndex, boolean isServerSideInserted)
Returns an instance with the specified value forAdPlaybackState.AdGroup.isServerSideInsertedin the specified ad group.
-
-