Enable Google DAI playback (iOS v3)
Enable ad playback with the Google Dynamic Ad Insertion ad client in an iOS app.
After adding the Google IMA Dynamic Ad Insertion (DAI) SDK to your app and acquiring the required items listed in the Requirements section, you can enable Google DAI ad playback in your iOS app.
Requirements
- JWP iOS SDK 3.11.0+
- All the JWP iOS SDK requirements
- Google DAI dependency
- All Google account information listed in the following table
| Property | Description |
|---|---|
apiKey NSString         | Stream request API key |
assetKey NSString | Stream asset key, used for live streams You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID. |
cmsID NSString | Content management system ID of the video, used for video on demand You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID. |
videoID NSString | Identifier of the DAI video to be displayed, used for video on demand You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID. |
Specify ad content for a single playlist item
Use the following steps to set up dynamic ad insertion for a single playlist item.
For the following reasons, be sure that the video URL (
videoURLin our code examples) used to set up the player is consistent with the media content registered with DAI for yourvideoIDorassetKey:• If the DAI request fails, the video URL will play as a fallback.
• Analytics will be attributed to correct media item.
- Define your Google account information.
• If you are displaying a video on demand, definecmsIDandvideoID.
• If you are displaying a live stream, defineassetKey. - Instantiate a
JWGoogimaDaiConfigobject. In our code example, we name thisdaiConfig.
• If you are displaying a video on demand, useinitWithVideoID:cmsID:.
• If you are displaying a live stream, useinitWithAssetKey:. - If your content is protected, set the
apiKeyproperty with your Google DAI API key. - Create a
JWAdConfigand set the client toJWAdClientGoogimaDAI. - Assign the
JWGoogimaDaiConfigto yourJWAdConfigand place it in yourJWConfig.
In the code examples below, we have added a JWGoogimaDaiConfig for a video-on-demand playlist item.
@property (nonatomic) JWPlayerController *player;
@property (nonatomic, weak) IBOutlet UIView *playerContainerView;
@end
@implementation ObjCViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create the DAI Config
JWGoogimaDaiConfig *daiConfig = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO_ID cmsID:CMS_ID];
daiConfig.apiKey = API_KEY;
// Create the Ad Config
JWAdConfig *adConfig = [JWAdConfig new];
adConfig.client = JWAdClientGoogimaDAI;
adConfig.googimaDaiSettings = daiConfig;
// Initialize the JWConfig and create the JWPlayerController
// The content URL supplied here will be used if the DAI video fails to load.
JWConfig *config = [JWConfig configWithContentURL:FALLBACK_CONTENT_URL];
config.advertising = adConfig;
self.player = [[JWPlayerController alloc] initWithConfig:config];
}
- (void)viewDidAppear {
[super viewDidAppear];
[self.view addSubview:self.player.view];
}
class ViewController: UIViewController {
@IBOutlet weak var playerContainerView: UIView!
var player: JWPlayerController?
override func viewDidLoad() {
super.viewDidLoad()
// Create the DAI Config
let daiConfig = JWGoogimaDaiConfig(videoID: VIDEO_ID, cmsID: CMS_ID)
daiConfig.apiKey = API_KEY
// Create the Ad Config
let adConfig = JWAdConfig()
adConfig.client = .googimaDAI
adConfig.googimaDaiSettings = daiConfig
// Initialize the JWConfig and create the JWPlayerController
// The content URL supplied here will be used if the DAI video fails to load.
let config = JWConfig(contentURL: FALLBACK_CONTENT_URL)
config.advertising = adConfig
player = JWPlayerController(config: config)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
playerContainerView.addSubview(player!.view)
}
}
Specify ad content for multiple playlist items
Use the following steps to associate new DAI ad content with another playlist item. You should follow the steps in the previous section first.
- Define your Google account information.
• If you are displaying a video on demand, define create newcmsIDandvideoIDproperties.
• If you are displaying a live stream, define a newassetKeyproperty. - For a specific
JWPlaylistItem, create aJWGoogimaDaiConfigobject.
• If you are displaying a video on demand, useinitWithVideoID:cmsID:.
• If you are displaying a live stream, useinitWithAssetKey:. - If your content is protected, set the
apiKeyproperty with your Google DAI API key. - Assign the
JWGoogimaDaiConfigto theJWPlaylistItem. - Repeat steps 1-4 to associate DAI ad content with another playlist item.
@property (nonatomic) JWPlayerController *player;
@property (nonatomic, weak) IBOutlet UIView *playerContainerView;
@end
@implementation ObjCViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create the playlist items, and give them their own unique DAI configs
JWPlaylistItem *item = [JWPlaylistItem new];
item.file = FALLBACK_CONTENT_URL;
item.googimaDaiSettings = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO_ID cmsID:CMS_ID];
JWPlaylistItem *item2 = [JWPlaylistItem new];
item2.file = FALLBACK_CONTENT2_URL;
item2.googimaDaiSettings = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO2_ID cmsID:CMS2_ID];
// Create the default DAI Config
// This config is used if a playlist item does not specify a DAI config.
JWGoogimaDaiConfig *daiConfig = [[JWGoogimaDaiConfig alloc] initWithVideoID:DEFAULT_VIDEO_ID cmsID:DEFAULT_CMS_ID];
daiConfig.apiKey = API_KEY;
// Create the Ad Config
JWAdConfig *adConfig = [JWAdConfig new];
adConfig.client = JWAdClientGoogimaDAI;
adConfig.googimaDaiSettings = daiConfig;
// Initialize the JWConfig and create the JWPlayerController
// The content URL supplied here will be used if the DAI video fails to load.
JWConfig *config = [JWConfig configWithContentURL:DEFAULT_FALLBACK_CONTENT_URL];
config.advertising = adConfig;
config.playlist = @[item, item2];
self.player = [[JWPlayerController alloc] initWithConfig:config];
}
- (void)viewDidAppear {
[super viewDidAppear];
[self.view addSubview:self.player.view];
}
class ViewController: UIViewController {
@IBOutlet weak var playerContainerView: UIView!
var player: JWPlayerController?
override func viewDidLoad() {
super.viewDidLoad()
// Create the playlist items, and give them their own unique DAI configs
let item = JWPlaylistItem()
item.file = FALLBACK_CONTENT_URL
item.googimaDaiSettings = JWGoogimaDaiConfig(videoID: VIDEO_ID, cmsID: CMS_ID)
let item2 = JWPlaylistItem()
item2.file = FALLBACK_CONTENT2_URL
item2.googimaDaiSettings = JWGoogimaDaiConfig(videoID: VIDEO2_ID, cmsID: CMS2_ID)
// Create the default DAI Config
// This config is used if a playlist item does not specify a DAI config.
let daiConfig = JWGoogimaDaiConfig(videoID: DEFAULT_VIDEO_ID, cmsID: DEFAULT_CMS_ID)
daiConfig.apiKey = API_KEY
// Create the Ad Config
let adConfig = JWAdConfig()
adConfig.client = .googimaDAI
adConfig.googimaDaiSettings = daiConfig
// Initialize the JWConfig and create the JWPlayerController
// The content URL supplied here will be used if the DAI video fails to load.
let config = JWConfig(contentURL: DEFAULT_FALLBACK_CONTENT_URL)
config.advertising = adConfig
config.playlist = [item, item2]
player = JWPlayerController(config: config)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
playerContainerView.addSubview(player!.view)
}
}
FAQ
Which iOS SDK features are not supported with Google DAI?
The following iOS SDK features are not supported with Google DAI:
- Side-loaded captions
- Chromecast and Airplay
- Use of seek API during ad playback
- Use of playbackRate API
- Stream request Auth token
Updated almost 3 years ago
