Skip to content

Commit

Permalink
Fix handling of ad tags with only preroll and postroll ads
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrewlewis authored and ojw28 committed Feb 20, 2018
1 parent 4276a19 commit 95f298f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,14 @@ private void startAdPlayback() {
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 */ {
Expand All @@ -879,6 +878,11 @@ private void startAdPlayback() {
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();
Expand Down Expand Up @@ -1051,4 +1055,16 @@ private static boolean isAdGroupLoadError(AdError adError) {
// 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;
}
}
}

0 comments on commit 95f298f

Please sign in to comment.