Class AdPlaybackState.AdGroup
- java.lang.Object
-
- com.google.android.exoplayer2.source.ads.AdPlaybackState.AdGroup
-
- All Implemented Interfaces:
Bundleable
- Enclosing class:
- AdPlaybackState
public static final class AdPlaybackState.AdGroup extends Object implements Bundleable
Represents a group of ads, with information about their states.Instances are immutable. Call the
with*methods to get new instances that have the required changes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.Bundleable
Bundleable.Creator<T extends Bundleable>
-
-
Field Summary
Fields Modifier and Type Field Description longcontentResumeOffsetUsThe offset in microseconds which should be added to the content stream when resuming playback after the ad group.intcountThe number of ads in the ad group, orC.LENGTH_UNSETif unknown.static Bundleable.Creator<AdPlaybackState.AdGroup>CREATORObject that can restoreAdPlaybackState.AdGroupfrom aBundle.long[]durationsUsThe durations of each ad in the ad group, in microseconds.booleanisServerSideInsertedWhether this ad group is server-side inserted and part of the content stream.intoriginalCountThe original number of ads in the ad group in case the ad group is only partially available, orC.LENGTH_UNSETif unknown.@com.google.android.exoplayer2.source.ads.AdPlaybackState.AdState int[]statesThe state of each ad in the ad group.longtimeUsThe time of the ad group in theTimeline.Period, in microseconds, orC.TIME_END_OF_SOURCEto indicate a postroll ad.@NullableType Uri[]urisThe URI of each ad in the ad group.
-
Constructor Summary
Constructors Constructor Description AdGroup(long timeUs)Creates a new ad group with an unspecified number of ads.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)intgetFirstAdIndexToPlay()Returns the index of the first ad in the ad group that should be played, orcountif no ads should be played.intgetNextAdIndexToPlay(int lastPlayedAdIndex)Returns the index of the next ad in the ad group that should be played after playinglastPlayedAdIndex, orcountif no later ads should be played.inthashCode()booleanhasUnplayedAds()Returns whether the ad group has at least one ad that is neither played, skipped, nor failed.booleanshouldPlayAdGroup()Returns whether the ad group has at least one ad that should be played.BundletoBundle()Returns aBundlerepresenting the information stored in this object.AdPlaybackState.AdGroupwithAdCount(int count)Returns a new instance with the ad count set tocount.AdPlaybackState.AdGroupwithAdDurationsUs(long[] durationsUs)Returns a new instance with the specified ad durations, in microseconds.AdPlaybackState.AdGroupwithAdState(@com.google.android.exoplayer2.source.ads.AdPlaybackState.AdState int state, int index)Returns a new instance with the specified ad set to the specifiedstate.AdPlaybackState.AdGroupwithAdUri(Uri uri, int index)Returns a new instance with the specifieduriset for the specified ad, and the ad marked asAdPlaybackState.AD_STATE_AVAILABLE.AdPlaybackState.AdGroupwithAllAdsReset()Returns an instance with all ads in final states (played, skipped, error) reset to either available or unavailable, which allows to play them again.AdPlaybackState.AdGroupwithAllAdsSkipped()Returns an instance with all unavailable and available ads marked as skipped.AdPlaybackState.AdGroupwithContentResumeOffsetUs(long contentResumeOffsetUs)Returns an instance with the specifiedcontentResumeOffsetUs.AdPlaybackState.AdGroupwithIsServerSideInserted(boolean isServerSideInserted)Returns an instance with the specified value forisServerSideInserted.AdPlaybackState.AdGroupwithLastAdRemoved()Removes the last ad from the ad group.AdPlaybackState.AdGroupwithOriginalAdCount(int originalCount)Returns an instance with the specified value fororiginalCount.AdPlaybackState.AdGroupwithTimeUs(long timeUs)Returns a new instance with thetimeUsset to the specified value.
-
-
-
Field Detail
-
timeUs
public final long timeUs
The time of the ad group in theTimeline.Period, in microseconds, orC.TIME_END_OF_SOURCEto indicate a postroll ad.
-
count
public final int count
The number of ads in the ad group, orC.LENGTH_UNSETif unknown.
-
originalCount
public final int originalCount
The original number of ads in the ad group in case the ad group is only partially available, orC.LENGTH_UNSETif unknown. An ad can be partially available when a server side inserted ad live stream is joined while an ad is already playing and some ad information is missing.
-
uris
public final @NullableType Uri[] uris
The URI of each ad in the ad group.
-
states
@AdState public final @com.google.android.exoplayer2.source.ads.AdPlaybackState.AdState int[] states
The state of each ad in the ad group.
-
durationsUs
public final long[] durationsUs
The durations of each ad in the ad group, in microseconds.
-
contentResumeOffsetUs
public final long contentResumeOffsetUs
The offset in microseconds which should be added to the content stream when resuming playback after the ad group.
-
isServerSideInserted
public final boolean isServerSideInserted
Whether this ad group is server-side inserted and part of the content stream.
-
CREATOR
public static final Bundleable.Creator<AdPlaybackState.AdGroup> CREATOR
Object that can restoreAdPlaybackState.AdGroupfrom aBundle.
-
-
Constructor Detail
-
AdGroup
public AdGroup(long timeUs)
Creates a new ad group with an unspecified number of ads.- Parameters:
timeUs- The time of the ad group in theTimeline.Period, in microseconds, orC.TIME_END_OF_SOURCEto indicate a postroll ad.
-
-
Method Detail
-
getFirstAdIndexToPlay
public int getFirstAdIndexToPlay()
Returns the index of the first ad in the ad group that should be played, orcountif no ads should be played.
-
getNextAdIndexToPlay
public int getNextAdIndexToPlay(@IntRange(from=-1L) int lastPlayedAdIndex)Returns the index of the next ad in the ad group that should be played after playinglastPlayedAdIndex, orcountif no later ads should be played. If no ads have been played, pass -1 to get the index of the first ad to play.Note: Server side inserted ads are always considered playable.
-
shouldPlayAdGroup
public boolean shouldPlayAdGroup()
Returns whether the ad group has at least one ad that should be played.
-
hasUnplayedAds
public boolean hasUnplayedAds()
Returns whether the ad group has at least one ad that is neither played, skipped, nor failed.
-
withTimeUs
@CheckResult public AdPlaybackState.AdGroup withTimeUs(long timeUs)
Returns a new instance with thetimeUsset to the specified value.
-
withAdCount
@CheckResult public AdPlaybackState.AdGroup withAdCount(int count)
Returns a new instance with the ad count set tocount.
-
withAdUri
@CheckResult public AdPlaybackState.AdGroup withAdUri(Uri uri, @IntRange(from=0L) int index)
Returns a new instance with the specifieduriset for the specified ad, and the ad marked asAdPlaybackState.AD_STATE_AVAILABLE.
-
withAdState
@CheckResult public AdPlaybackState.AdGroup withAdState(@AdState @com.google.android.exoplayer2.source.ads.AdPlaybackState.AdState int state, @IntRange(from=0L) int index)
Returns a new instance with the specified ad set to the specifiedstate. The ad specified must currently either be inAdPlaybackState.AD_STATE_UNAVAILABLEorAdPlaybackState.AD_STATE_AVAILABLE.This instance's ad count may be unknown, in which case
indexmust be less than the ad count specified later. Otherwise,indexmust be less than the current ad count.
-
withAdDurationsUs
@CheckResult public AdPlaybackState.AdGroup withAdDurationsUs(long[] durationsUs)
Returns a new instance with the specified ad durations, in microseconds.
-
withContentResumeOffsetUs
@CheckResult public AdPlaybackState.AdGroup withContentResumeOffsetUs(long contentResumeOffsetUs)
Returns an instance with the specifiedcontentResumeOffsetUs.
-
withIsServerSideInserted
@CheckResult public AdPlaybackState.AdGroup withIsServerSideInserted(boolean isServerSideInserted)
Returns an instance with the specified value forisServerSideInserted.
-
withOriginalAdCount
public AdPlaybackState.AdGroup withOriginalAdCount(int originalCount)
Returns an instance with the specified value fororiginalCount.
-
withLastAdRemoved
public AdPlaybackState.AdGroup withLastAdRemoved()
Removes the last ad from the ad group.
-
withAllAdsSkipped
@CheckResult public AdPlaybackState.AdGroup withAllAdsSkipped()
Returns an instance with all unavailable and available ads marked as skipped. If the ad count hasn't been set, it will be set to zero.
-
withAllAdsReset
@CheckResult public AdPlaybackState.AdGroup withAllAdsReset()
Returns an instance with all ads in final states (played, skipped, error) reset to either available or unavailable, which allows to play them again.
-
toBundle
public Bundle toBundle()
Description copied from interface:BundleableReturns aBundlerepresenting the information stored in this object.- Specified by:
toBundlein interfaceBundleable
-
-