Skip to content

Ensures errors are correctly attributed to ad or content #2655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,23 @@ public void activate(Player player) {
/** Deactivates playback. */
public void deactivate() {
Player player = checkNotNull(this.player);
if (!AdPlaybackState.NONE.equals(adPlaybackState) && imaPausedContent) {
// Post release of listener behind any already queued Player.Listener events to ensure that
// any pending events are processed before the player is deferred.
handler.post(
() -> {
deactivateInternal(player);
});
}

/**
* Deactivates playback internally, after the Listener.onEvents() cycle completes so the complete
* state change picture is clear. For example, if an error caused the deactivation, need to
* determine whether the error was for an ad or content.
*/
private void deactivateInternal(Player player) {
if (!AdPlaybackState.NONE.equals(adPlaybackState)
&& imaPausedContent
&& player.getPlayerError() == null) {
if (adsManager != null) {
adsManager.pause();
}
Expand All @@ -402,9 +418,7 @@ public void deactivate() {
lastVolumePercent = getPlayerVolumePercent();
lastAdProgress = getAdVideoProgressUpdate();
lastContentProgress = getContentVideoProgressUpdate();

// Post release of listener so that we can report any already pending errors via onPlayerError.
handler.post(() -> player.removeListener(this));
player.removeListener(this);
this.player = null;
}

Expand Down Expand Up @@ -539,7 +553,7 @@ public void onPlayWhenReadyChanged(

@Override
public void onPlayerError(PlaybackException error) {
if (imaAdState != IMA_AD_STATE_NONE) {
if (imaAdState != IMA_AD_STATE_NONE && player.isPlayingAd()) {
AdMediaInfo adMediaInfo = checkNotNull(imaAdMediaInfo);
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onError(adMediaInfo);
Expand Down