Commit e913ede7 by andrewlewis Committed by Oliver Woodman

Fix condition for detecting that an ad has ended

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
parent 65360760
...@@ -703,6 +703,9 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -703,6 +703,9 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
for (int i = 0; i < adCallbacks.size(); i++) { for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded(); adCallbacks.get(i).onEnded();
} }
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onPlayerStateChanged");
}
} }
} }
...@@ -798,16 +801,20 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -798,16 +801,20 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
private void updateImaStateForPlayerState() { private void updateImaStateForPlayerState() {
boolean wasPlayingAd = playingAd; boolean wasPlayingAd = playingAd;
int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup;
playingAd = player.isPlayingAd(); playingAd = player.isPlayingAd();
playingAdIndexInAdGroup = playingAd ? player.getCurrentAdIndexInAdGroup() : C.INDEX_UNSET;
if (!sentContentComplete) { if (!sentContentComplete) {
boolean adFinished = (wasPlayingAd && !playingAd) boolean adFinished = wasPlayingAd && playingAdIndexInAdGroup != oldPlayingAdIndexInAdGroup;
|| playingAdIndexInAdGroup != player.getCurrentAdIndexInAdGroup();
if (adFinished) { if (adFinished) {
// IMA is waiting for the ad playback to finish so invoke the callback now. // 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. // Either CONTENT_RESUME_REQUESTED will be passed next, or playAd will be called again.
for (int i = 0; i < adCallbacks.size(); i++) { for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded(); adCallbacks.get(i).onEnded();
} }
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onTimelineChanged/onPositionDiscontinuity");
}
} }
if (!wasPlayingAd && playingAd) { if (!wasPlayingAd && playingAd) {
int adGroupIndex = player.getCurrentAdGroupIndex(); int adGroupIndex = player.getCurrentAdGroupIndex();
...@@ -819,7 +826,6 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -819,7 +826,6 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
} }
} }
} }
playingAdIndexInAdGroup = playingAd ? player.getCurrentAdIndexInAdGroup() : C.INDEX_UNSET;
} }
private void resumeContentInternal() { private void resumeContentInternal() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment