mirror of
https://github.com/androidx/media.git
synced 2025-05-11 01:31:40 +08:00
Merge pull request #4442 from keiththompson/keiththompson__/skip_ad_within_ad_group
Add withSkippedAd method to AdPlaybackState.
This commit is contained in:
commit
423cfa3b73
@ -368,6 +368,14 @@ public final class AdPlaybackState {
|
||||
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
|
||||
}
|
||||
|
||||
/** Returns an instance with the specified ad marked as skipped. */
|
||||
@CheckResult
|
||||
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
|
||||
AdGroup[] adGroups = Arrays.copyOf(this.adGroups, this.adGroups.length);
|
||||
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
|
||||
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
|
||||
}
|
||||
|
||||
/** Returns an instance with the specified ad marked as having a load error. */
|
||||
@CheckResult
|
||||
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
|
||||
|
@ -89,6 +89,19 @@ public final class AdPlaybackStateTest {
|
||||
assertThat(state.adGroups[0].states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstAdIndexToPlaySkipsSkippedAd() {
|
||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||
|
||||
state = state.withSkippedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
||||
|
||||
assertThat(state.adGroups[0].getFirstAdIndexToPlay()).isEqualTo(1);
|
||||
assertThat(state.adGroups[0].states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
||||
assertThat(state.adGroups[0].states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstAdIndexToPlaySkipsErrorAds() {
|
||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user