Skip to content

Commit

Permalink
Fix condition for detecting that an ad has ended
Browse files Browse the repository at this point in the history
onEnded was being called also for content finishing, as in this case the playing
ad index changed (from INDEX_UNSET to 0). Fix this test so we only detect ads
finishing.

Also add logging for onEnded callbacks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179167737
  • Loading branch information
andrewlewis authored and ojw28 committed Dec 15, 2017
1 parent b97ce44 commit 04108ee
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded();
}
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onPlayerStateChanged");
}
}
}

Expand Down Expand Up @@ -797,16 +800,20 @@ private void maybeNotifyAdError() {

private void updateImaStateForPlayerState() {
boolean wasPlayingAd = playingAd;
int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup;
playingAd = player.isPlayingAd();
playingAdIndexInAdGroup = playingAd ? player.getCurrentAdIndexInAdGroup() : C.INDEX_UNSET;
if (!sentContentComplete) {
boolean adFinished = (wasPlayingAd && !playingAd)
|| playingAdIndexInAdGroup != player.getCurrentAdIndexInAdGroup();
boolean adFinished = wasPlayingAd && playingAdIndexInAdGroup != oldPlayingAdIndexInAdGroup;
if (adFinished) {
// IMA is waiting for the ad playback to finish so invoke the callback now.
// Either CONTENT_RESUME_REQUESTED will be passed next, or playAd will be called again.
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded();
}
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onTimelineChanged/onPositionDiscontinuity");
}
}
if (!wasPlayingAd && playingAd) {
int adGroupIndex = player.getCurrentAdGroupIndex();
Expand All @@ -818,7 +825,6 @@ private void updateImaStateForPlayerState() {
}
}
}
playingAdIndexInAdGroup = playingAd ? player.getCurrentAdIndexInAdGroup() : C.INDEX_UNSET;
}

private void resumeContentInternal() {
Expand Down

0 comments on commit 04108ee

Please sign in to comment.