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

PropertyDescription
apiKey NSString Β Β Β Β Β Β Β Β Stream request API key
assetKey NSStringStream 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 NSStringContent 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 NSStringIdentifier 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 (videoURL in our code examples) used to set up the player is consistent with the media content registered with DAI for your videoID or assetKey:

β€’ If the DAI request fails, the video URL will play as a fallback.
β€’ Analytics will be attributed to correct media item.


  1. Define your Google account information.
    β€’ If you are displaying a video on demand, define cmsID and videoID.
    β€’ If you are displaying a live stream, define assetKey.
  2. Instantiate a JWGoogimaDaiConfig object. In our code example, we name this daiConfig.
    β€’ If you are displaying a video on demand, use initWithVideoID:cmsID:.
    β€’ If you are displaying a live stream, use initWithAssetKey:.
  3. If your content is protected, set the apiKey property with your Google DAI API key.
  4. Create a JWAdConfig and set the client to JWAdClientGoogimaDAI.
  5. Assign the JWGoogimaDaiConfig to your JWAdConfig and place it in your JWConfig.

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.

  1. Define your Google account information.
    β€’ If you are displaying a video on demand, define create new cmsID and videoID properties.
    β€’ If you are displaying a live stream, define a new assetKey property.
  2. For a specific JWPlaylistItem, create a JWGoogimaDaiConfig object.
    β€’ If you are displaying a video on demand, use initWithVideoID:cmsID:.
    β€’ If you are displaying a live stream, use initWithAssetKey:.
  3. If your content is protected, set the apiKey property with your Google DAI API key.
  4. Assign the JWGoogimaDaiConfig to the JWPlaylistItem.
  5. 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