Fix handling of ad tags with only preroll and postroll ads

Content progress is only polled if there are midroll ad groups. If the ad tag
had only preroll/postroll ads, the pending content position was not provided to
IMA, which meant that the postroll ad could never play.

Only set the pending content position if there are midroll ads.

Issue: #3715

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=185680803
This commit is contained in:
andrewlewis 2018-02-14 07:03:40 -08:00 committed by Oliver Woodman
parent 4276a199ba
commit 95f298f5a4
2 changed files with 21 additions and 3 deletions

View File

@ -97,6 +97,8 @@
([#3676](https://github.com/google/ExoPlayer/issues/3676)).
* Fix handling of ad tags where ad groups are out of order
([#3716](https://github.com/google/ExoPlayer/issues/3716)).
* Fix handling of ad tags with only preroll/postroll ad groups
([#3715](https://github.com/google/ExoPlayer/issues/3715)).
* Propagate ad media preparation errors to IMA so that the ads can be
skipped.
* `EventLogger` moved from the demo app into the core library.

View File

@ -851,15 +851,14 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
adsRenderingSettings.setMimeTypes(supportedMimeTypes);
// Set up the ad playback state, skipping ads based on the start position as required.
pendingContentPositionMs = player.getCurrentPosition();
long[] adGroupTimesUs = getAdGroupTimesUs(adsManager.getAdCuePoints());
adPlaybackState = new AdPlaybackState(adGroupTimesUs);
long contentPositionMs = player.getCurrentPosition();
int adGroupIndexForPosition =
adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(pendingContentPositionMs));
adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentPositionMs));
if (adGroupIndexForPosition == 0) {
podIndexOffset = 0;
} else if (adGroupIndexForPosition == C.INDEX_UNSET) {
pendingContentPositionMs = C.TIME_UNSET;
// There is no preroll and midroll pod indices start at 1.
podIndexOffset = -1;
} else /* adGroupIndexForPosition > 0 */ {
@ -879,6 +878,11 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
podIndexOffset = adGroupIndexForPosition - 1;
}
if (hasMidrollAdGroups(adGroupTimesUs)) {
// IMA will poll the content position, so provide the player's initial position like a seek.
pendingContentPositionMs = contentPositionMs;
}
// Start ad playback.
adsManager.init(adsRenderingSettings);
updateAdPlaybackState();
@ -1051,4 +1055,16 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
// a single ad, ad group or the whole timeline.
return adError.getErrorCode() == AdErrorCode.VAST_LINEAR_ASSET_MISMATCH;
}
private static boolean hasMidrollAdGroups(long[] adGroupTimesUs) {
int count = adGroupTimesUs.length;
if (count == 1) {
return adGroupTimesUs[0] != 0 && adGroupTimesUs[0] != C.TIME_END_OF_SOURCE;
} else if (count == 2) {
return adGroupTimesUs[0] != 0 || adGroupTimesUs[1] != C.TIME_END_OF_SOURCE;
} else {
// There's at least one midroll ad group, as adGroupTimesUs is never empty.
return true;
}
}
}