Skip to content

Skip mediation banner refresh while a Prebid video is playing - #1020

Open
mdanylov-sigma wants to merge 1 commit into
masterfrom
feature/1017-mediation-video-refresh-gate
Open

mdanylov-sigma wants to merge 1 commit into
masterfrom
feature/1017-mediation-video-refresh-gate

Conversation

@mdanylov-sigma

Copy link
Copy Markdown
Collaborator

Closes #1017.

Problem

BannerView skips a refresh tick while a Prebid video creative is playing, so the creative is never torn down mid playback. MediationBannerAdUnit has no equivalent gate — its refresh listener only checks mediationDelegate.canPerformRefresh() and screenStateReceiver.isScreenOn(). A multiformat mediation banner with a refresh interval shorter than its video creative gets cut off.

#1010 left this out on the grounds that a mediation ad unit is not told whether the Prebid bid won in the primary ad server. That is true, but it is not what the gate needs to know.

Approach

Mirrors iOS MediationBannerAdUnit.swift, which reads the playback state off whatever is actually rendered rather than off the auction's outcome:

  • PrebidMediationDelegate gains getAdView(), the counterpart of iOS's PrebidMediationDelegate.getAdView().
  • MediationBannerView — the container both adapters render into — exposes isVideoPlaying(), same shape as DisplayView.isVideoPlaying() from Multiformat banner ad unit in the rendering and mediation APIs #1010.
  • MediationBannerAdUnit.isVideoPlaying() walks the mediation SDK's ad view for that container and reads the flag; initBidLoader()'s refresh listener skips the tick when it is true. As on iOS, the timer is only skipped, not cancelled, so refreshing resumes on its own once playback finishes.

Because the gate is driven by "is a Prebid creative currently playing", it reports false when another demand partner won the mediation auction, with no need for the ad unit to learn who won.

getAdView() is a default method returning null, matching how onAdExpired and getReward were added to their interfaces. The interstitial and rewarded utils, and any publisher's own PrebidMediationDelegate, keep compiling and simply opt out of the gate — the setAdUnitFormats javadoc now says so, and points those publishers at stopRefresh()/resumeRefresh().

Changes

File Change
PrebidMediationDelegate new default View getAdView() returning null
AdMobMediationBannerUtils, MaxMediationBannerUtils return the weakly held ad view
MediationBannerView new isVideoPlaying()
MediationBannerAdUnit isVideoPlaying() gate in the refresh listener; javadoc
Views new findFirstDescendantOfType(), the counterpart of iOS's UIView.firstDescendant(of:)

Testing

MediationBannerAdUnitTest covers the tick being skipped during playback, allowed after playback, allowed after onAdFailed() even while video reports playing, and isVideoPlaying() returning false with no Prebid view in the hierarchy, no ad view, and a delegate that does not implement getAdView(). New ViewsTest covers the hierarchy walk.

:PrebidMobile-core:testDebugUnitTest passes except MraidInternalBrowserActionTest > handleInternalBrowserActionFollowUrlSuccessAndIsMraid_StartActionViewActivity, which fails on master as well and is unrelated to this change.

🤖 Generated with Claude Code

MediationBannerAdUnit's refresh listener only checked the mediation SDK's
visibility and the screen state, so a refresh tick could tear down a Prebid
video creative mid playback. BannerView already skips the tick in that case.

Mirror what iOS does in MediationBannerAdUnit.swift: read the playback state
off whatever is actually rendered, rather than off the auction's outcome.
PrebidMediationDelegate gains getAdView(), the mediation SDK's ad view is
walked for the MediationBannerView the adapter rendered into, and the tick is
skipped while that view reports a playing video. The gate therefore clears on
its own when playback finishes or when another demand partner wins.

getAdView() is a default method returning null, so existing delegates - the
interstitial and rewarded utils, and any publisher's own implementation - keep
compiling and simply opt out of the gate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mdanylov-sigma
mdanylov-sigma force-pushed the feature/1017-mediation-video-refresh-gate branch from 2034731 to 4020cab Compare November 30, 2026 17:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MediationBannerAdUnit doesn't skip refresh while a Prebid video creative is playing

2 participants