Preroll Ads
Preroll ads are video ads that play before your content in a video player container. The SDK manages playback automatically using Google IMA — the ad auto-plays with no user-visible controls. Users can skip the ad when the VAST creative allows it.
After the ad completes, is skipped, or fails, the content video plays automatically with standard player controls. No additional handling is needed.
Each ad format uses a Zone ID to identify the ad placement. Zone IDs are configured in the Empower dashboard.
Note: All ad delegates are optional. The SDK handles ad loading, playback, and content fallback automatically. Use delegates only if you need to track ad states for analytics or UI updates.
Container Setup
Add a UIView to your layout as the video ad container:
- Storyboard
- Programmatic
Create a UIView in your storyboard and connect it as an IBOutlet:
@IBOutlet weak var playerView: UIView!
Loading a Preroll Ad
- UIKit
- SwiftUI
import EmpowerMobileAdsclass VideoViewController: UIViewController {@IBOutlet weak var playerView: UIView!override func viewDidLoad() {super.viewDidLoad()EMAManager.shared.loadVideoAd(zoneId: "YOUR_PREROLL_ZONE_ID",in: playerView,delegate: self) { [weak self] success inif success {self?.prerollManager?.showVideoAd()}}}}
That's it — the SDK loads the ad, plays it, and transitions to your content video automatically.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
zoneId | String? | No | nil | The zone ID for the preroll placement. When nil, the first available video zone is used |
in | UIView | Yes | — | The container view where the ad and content will play |
delegate | AdStatusDelegate? | No | nil | Delegate to receive ad status changes and IMA events |
completion | ((Bool) -> Void)? | No | nil | Called when ad loading completes. true if the ad is ready to show |
Listening to Preroll Events (Optional)
Use AdStatusDelegate if you need to react to specific ad events:
- Status Delegate
- IMA Events
extension VideoViewController: AdStatusDelegate {func videoAdStatusChanged(_ manager: EmpowerVideoAdManager) {switch manager.status {case .ready:// Ad loaded and about to playbreakcase .active:// Ad is playingbreakcase .completePlaying:// Ad finished — start content videostartContentPlayback()manager.cleanup()case .failed:// Ad failed — start content video automaticallystartContentPlayback()manager.cleanup()default:break}}}
Lifecycle Management
The SDK automatically manages the ad lifecycle based on the view controller's state. 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 UICollectionView or UITableView, use:
// Pause playback (e.g., cell scrolled off-screen)prerollManager?.pause()// Resume playback (e.g., cell scrolled back)prerollManager?.resume()
Always clean up resources when the ad is no longer needed:
// When the view controller is deallocateddeinit {prerollManager?.cleanup()}
| Method | Description |
|---|---|
cleanup() | Releases IMA resources, removes ad container, and clears delegate references |
showVideoAd() | Starts ad playback after a successful load |
getAdContainerView() | Returns the ad container view if created |
Best Practices
- Always set
rootViewController— IMA requires it for proper ad presentation. SetEMASettings.shared.rootViewControllerin yourAppDelegate - Mute when appropriate — Use server-side VAST settings if the video auto-plays in a feed or silent context
- Frequency capping — The SDK respects server-configured session frequency caps.
Ad Status Reference
| Status | Description |
|---|---|
.ready | Ad is loaded and about to play |
.active | Ad is playing |
.completePlaying | Ad finished playing, content video is now playing |
.failed | Ad failed, content video is playing automatically |