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:

Create a UIView in your storyboard and connect it as an IBOutlet:

@IBOutlet weak var playerView: UIView!

Loading a Preroll Ad

import EmpowerMobileAds
class 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 in
if success {
self?.prerollManager?.showVideoAd()
}
}
}
}

That's it — the SDK loads the ad, plays it, and transitions to your content video automatically.

Parameters

ParameterTypeRequiredDefaultDescription
zoneIdString?NonilThe zone ID for the preroll placement. When nil, the first available video zone is used
inUIViewYesThe container view where the ad and content will play
delegateAdStatusDelegate?NonilDelegate to receive ad status changes and IMA events
completion((Bool) -> Void)?NonilCalled 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:

extension VideoViewController: AdStatusDelegate {
func videoAdStatusChanged(_ manager: EmpowerVideoAdManager) {
switch manager.status {
case .ready:
// Ad loaded and about to play
break
case .active:
// Ad is playing
break
case .completePlaying:
// Ad finished — start content video
startContentPlayback()
manager.cleanup()
case .failed:
// Ad failed — start content video automatically
startContentPlayback()
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 deallocated
deinit {
prerollManager?.cleanup()
}
MethodDescription
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. Set EMASettings.shared.rootViewController in your AppDelegate
  • 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

StatusDescription
.readyAd is loaded and about to play
.activeAd is playing
.completePlayingAd finished playing, content video is now playing
.failedAd failed, content video is playing automatically