Enable Google DAI playback

Enable ad playback with the Google Dynamic Ad Insertion ad client in an Android 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 Android app.



Requirements

PropertyDescription
adTagParameters Map<String, String>Limited set of key-value pairs that enable the player to override default information with custom information during a stream request

These key-value pairs should be properly formatted without encoding. See: Supply Targeting Parameters to Your Stream.
apiKey String                                             Stream request API key
assetKey StringStream 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 StringContent 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 StringIdentifier 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 playlist item.

👍

IMPORTANT

For the following reasons, be sure that the URL used for the PlaylistItem.file 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. If your content is protected, set the apiKey property with your Google DAI API key.
  3. Instantiate an ImaDaiSettings object. In our code example, we name this imaDaiSettings.
  4. If you have custom ad tag parameters, add them to the settings object with the setAdTagParameters() method.
  5. Add the ImaDaiSettings object to the imaDaiSettings property of the PlaylistItem object.
String cmsId = "CMS_ID";
String videoId = "VIDEO_ID";
// apiKey can be null
String apiKey = "YOUR_API_KEY";
//Set the stream type to HLS or Dash
ImaDaiSettings.StreamType streamType = ImaDaiSettings.StreamType.HLS;
ImaDaiSettings imaDaiSettings = new ImaDaiSettings(cmsId, videoId, streamType, apiKey);

// Add your custom parameters here
Map<String, String> tagParams = new HashMap<>();
tagParams.put("cust_params", "sport=football&city=newyork");
imaDaiSettings.setAdTagParameters(tagParams);

List<PlaylistItem> playlist = new ArrayList<>();
// Setup a media source
PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://content.jwplatform.com/manifests/{MEDIA_ID}.m3u8")
    .imaDaiSettings(imaDaiSettings)
    .build();

playlist.add(playlistItem);

PlayerConfig config = new PlayerConfig.Builder()
    .playlist(playlist)
    .build();

getPlayer().setup(config);
String assetKey = "YOUR_ASSET_KEY";
// apiKey can be null
String apiKey = "YOUR_API_KEY";
//Set the stream type to HLS or Dash
ImaDaiSettings.StreamType streamType = ImaDaiSettings.StreamType.HLS;
ImaDaiSettings imaDaiSettings = new ImaDaiSettings(assetKey, streamType, apiKey);

// Add your custom parameters here
Map<String, String> tagParams = new HashMap<>();
tagParams.put("cust_params", "sport=football&city=newyork");
imaDaiSettings.setAdTagParameters(tagParams);

// Setup a media source
PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://content.jwplatform.com/manifests/{MEDIA_ID}.m3u8")
    .imaDaiSettings(imaDaiSettings)
    .build();
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);

PlayerConfig config = new PlayerConfig.Builder()
    .playlist(playlist)
    .build();

getPlayer().setup(config);


FAQ

Which Android SDK features are not supported with Google DAI?



Did this page help you?