-
Notifications
You must be signed in to change notification settings - Fork 8
Video Ad Integration
It is very easy to display video ads with Adform Advertising SDK, just configure an Inline or AdHesion ad view (as described in "Integrating Inline Ad", "Integrating AdHesion Ad") and set a master tag id configured for video ads. That's it.
Ad views have a property called videoSettings
, this property can be used to configure how video ads are displayed. There you can set closeButtonBehavior
, initialyMuted
, autoClose
and controlsStyle
settings.
closeButtonBehavior
- defines when the close button should be visible to the user, available values:
-
AFVideoAdCloseButtonBehaviorNoButton
- the ad doesn't show a close button. This is a default value forcloseButtonBehavior
. -
AFVideoAdCloseButtonBehaviorWhenFinished
- the close button appears when the ad has finished playing. -
AFVideoAdCloseButtonBehaviorAllways
- the close button is visible all the time.
initialyMuted
- as the name of the property suggests, it allows you to initially mute the video ad, later the user can unmute it by pressing the mute/unmute button on the ad. By default this property is true.
autoClose
- this property defines if the banner should automatically close when the video ad has finished playing. The default value of this property is false.
controlsStyle
- this property specifies what video controls visual style video player should use. You can choose from default and minimal styles.
It is possible to preload video ads before displaying them. To do so, you have to set ad view property showAdAutomatically
to false and call showAd
method manually when the ad has finished loading. The code snippet below shows you how to do that:
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Create a new ad inline object with Master tag id.
let banner = AFAdInline(masterTagId: masterTag, presenting: self)
// Set the delegate, to be informed when the ad will finish loading.
banner.delegate = self
// Disable the ad auto show function.
banner.showAdAutomatically = false
// Add the newly created ad view as a subview to your view controller's view.
view.addSubview(banner)
// Iniate ad loading.
banner.loadAd()
}
func adInlineDidLoadAd(_ adInline: AFAdInline) {
// Display the ad manually.
adInline.showAd()
}
Objective-C
- (void)viewDidLoad
{
[super viewDidLoad];
// Create a new ad inline object with Master tag id.
AFAdInline *banner = [[AFAdInline alloc] initWithMasterTagId:mtag presentingViewController:self];
// Set the delegate, to be informed when the ad will finish loading.
banner.delegate = self;
// Disable the ad auto show function.
banner.showAdAutomatically = NO;
// Add the newly created ad view as a subview to your view controller's view.
[self.view addSubview:banner];
// Iniate ad loading.
[banner loadAd];
}
// Implement the delegate method.
- (void)adInlineDidLoadAd:(AFAdInline *)adInline {
// Display the ad manually.
[adInline showAd];
}
Video ads have three additional callbacks in AFAdInlineDelegate
, which allow you to respond to video ad state changes. It has adInlineSartedVideoPlayback:muted:
, adInlineFinishedVideoPlayback:
and adInline:videoAdMuted:
delegate methods. The example below shows you how these methods can be used to silence background music playing in the app while the ads are playing with audio.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Create a new ad inline object with Master tag id.
let banner = AFAdInline(masterTagId: masterTag, presenting: self)
// Set the delegate, to be informed when the ad will finish loading.
banner.delegate = self
// Add the newly created ad view as a subview to your view controller's view.
view.addSubview(banner)
// Iniate ad loading.
banner.loadAd()
}
func adInlineSartedVideoPlayback(_ adInline: AFAdInline, muted: Bool) {
// Check if video ad is muted, if not pause the background music.
if !muted {
backgroundMusicPlayer.pause()
}
}
func adInlineFinishedVideoPlayback(_ adInline: AFAdInline) {
// When the ad has finished playing we resume the background music player.
backgroundMusicPlayer.resume()
}
func adInline(_ adInline: AFAdInline, videoAdMuted muted: Bool) {
if muted {
// If video ad was muted by the user, we resume background music player.
backgroundMusicPlayer.resume()
} else {
// If video ad was unmuted by the user, we pause the background music player.
backgroundMusicPlayer.pause()
}
}
Objective-C
- (void)viewDidLoad
{
[super viewDidLoad];
// First, configure a new ad view and load it.
AFAdInline *banner = [[AFAdInline alloc] initWithMasterTagId:mtag presentingViewController:self];
banner.delegate = self;
[self.view addSubview:banner];
[banner loadAd];
}
- (void)adInlineSartedVideoPlayback:(AFAdInline *)adInline muted:(BOOL )muted {
// Check if video ad is muted, if not pause the background music.
if (muted == false) {
[self.backgroundMusicPlayer pause];
}
}
- (void)adInlineFinishedVideoPlayback:(AFAdInline *)adInline {
// When the ad has finished playing we resume the background music player.
[self.backgroundMusicPlayer resume];
}
- (void)adInline:(AFAdInline *)adInline videoAdMuted:(BOOL )muted {
if (muted) {
// If video ad was muted by the user, we resume background music player.
[self.backgroundMusicPlayer resume];
} else {
// If video ad was unmuted by the user, we pause the background music player.
[self.backgroundMusicPlayer pause];
}
}
Video banners can be configured to display fallback HTML ads. In order to enable this feature, you need to set a fallback master tag for the placement displaying video ads. The example below shows you how to do it.
Objective-C
adView.videoSettings.fallbackMasterTagId = kYourMasterTagId;
For a complete example of how to integrate Adform video ads into your application, check out the sample app.
Basic integrations
- Integrating Inline Ad
- Integrating Full Screen Overlay Ad
- Integrating AdHesion Ad
- Integrating Interstitial Ad
- Video Ad Integration
- Debug mode
- Troubleshooting
Advanced integrations
- Advanced Inline Ad Integration
- Integrating Inline Ads in UITableView
- Advanced Full Screen Overlay Ad Integration
- Advanced Interstitial Ad Integration
- Instream Video Ads
Other
- Adding Custom Values
- Adding Keywords
- Adding Key Value Pairs
- Adding Search Words
- Location Tracking
- Security
- Ad Tags
- Header Bidding
- Changing ADX Domain
- Specifying banner loading behaviour
- Customizing in app browser
- GDPR
- US Privacy
- Localization
- In app deeplinks
Mediation adapters