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.
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
- Kotlin
- Java
val playerView = findViewById<PlayerView>(R.id.playerView)
EMAManager.loadPrerollAd(
zoneId = "YOUR_PREROLL_ZONE_ID",
playerView = playerView,
contentUrl = "https://example.com/your-content-video.mp4"
)
PlayerView playerView = findViewById(R.id.playerView);
EMAManager.INSTANCE.loadPrerollAd(
"YOUR_PREROLL_ZONE_ID",
playerView,
"https://example.com/your-content-video.mp4",
false,
null,
null
);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
zoneId | String | Yes | none | The zone ID for the preroll placement |
playerView | PlayerView | Yes | none | The Media3 PlayerView where the ad and content will play |
contentUrl | String | Yes | none | URL of the content video that plays after the ad |
muted | Boolean | No | false | Whether to mute audio during ad playback |
prerollListener | PrerollAdListener | No | null | Preroll-specific event listener |
adStatusListener | AdStatusListener | No | null | Generic ad status listener |
Listening to Preroll Events
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.
| Callback | Called 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:
- Kotlin
- Java
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() { }
}
)
EMAManager.INSTANCE.loadPrerollAd(
"YOUR_PREROLL_ZONE_ID",
playerView,
"https://example.com/your-content-video.mp4",
false,
new PrerollAdListener() {
@Override
public void onAdReady() { }
@Override
public void onAdStarted() { }
@Override
public void onAdCompleted() { }
@Override
public void onAdSkipped() { }
@Override
public void onAdFailed(String error) { }
@Override
public void onAdClicked() { }
},
null
);
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:
- Kotlin
- Java
EMAManager.pausePreroll("YOUR_PREROLL_ZONE_ID")
EMAManager.resumePreroll("YOUR_PREROLL_ZONE_ID")
EMAManager.INSTANCE.pausePreroll("YOUR_PREROLL_ZONE_ID");
EMAManager.INSTANCE.resumePreroll("YOUR_PREROLL_ZONE_ID");