Skip to main content

Preroll Ads

Preroll ads are video ads that play before your content in a PlayerView. The SDK manages playback automatically using Google IMA. The ad auto-plays with no user-visible controls. Users can skip the ad when the creative allows it.

Each ad format uses a Zone ID to identify the ad placement. Zone IDs are configured in the Empower dashboard.

tip

Load the preroll when your video screen opens. The ad plays first and your content video follows automatically, whether the ad completes, is skipped, or fails.


XML Layout Setup

Add a PlayerView to your layout:

<androidx.media3.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Loading a Preroll Ad

val playerView = findViewById<PlayerView>(R.id.playerView)

EMAManager.loadPrerollAd(
zoneId = "YOUR_PREROLL_ZONE_ID",
playerView = playerView,
contentUrl = "https://example.com/your-content-video.mp4"
)

Parameters

ParameterTypeRequiredDefaultDescription
zoneIdStringYesnoneThe zone ID for the preroll placement
playerViewPlayerViewYesnoneThe Media3 PlayerView where the ad and content will play
contentUrlStringYesnoneURL of the content video that plays after the ad
mutedBooleanNofalseWhether to mute audio during ad playback
prerollListenerPrerollAdListenerNonullPreroll-specific event listener
adStatusListenerAdStatusListenerNonullGeneric ad status listener

Listening to Preroll Events

The SDK handles playback and fallback

All ad listeners are optional. The SDK loads the ad, plays it, and falls back to your content video automatically. Use listeners only if you need to track ad states for analytics, UI updates.

CallbackCalled when
onAdReady()Ad loaded and about to auto-play
onAdStarted()Ad playback started
onAdCompleted()Ad finished, content video is now playing
onAdSkipped()User skipped the ad, content video is now playing
onAdFailed(error)Ad failed, content video is now playing
onAdClicked()User clicked the ad

If you need to react to preroll events:

EMAManager.loadPrerollAd(
zoneId = "YOUR_PREROLL_ZONE_ID",
playerView = playerView,
contentUrl = "https://example.com/your-content-video.mp4",
prerollListener = object : PrerollAdListener {
override fun onAdReady() { }
override fun onAdStarted() { }
override fun onAdCompleted() { }
override fun onAdSkipped() { }
override fun onAdFailed(error: String) { }
override fun onAdClicked() { }
}
)

Lifecycle Management

The SDK automatically observes the Activity lifecycle through the PlayerView's context. Pause, resume, and cleanup are handled for you, no manual lifecycle calls are needed.

For special cases like pausing playback when the view scrolls off-screen in a RecyclerView, use:

EMAManager.pausePreroll("YOUR_PREROLL_ZONE_ID")

EMAManager.resumePreroll("YOUR_PREROLL_ZONE_ID")