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
- JW Player Android SDK 3.12.0+
- All the JW Player Android SDK requirements
- Google DAI dependency
- All Google account information listed in the following table
Property | Type | Description |
---|---|---|
adTagParameters 3.19.0+ |
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 |
String | 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 |
String | 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 |
String | 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 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.
- Define your Google account information.
• If you are displaying a video on demand, definecmsID
andvideoID
.
• If you are displaying a live stream, defineassetKey
. - If your content is protected, set the
apiKey
property with your Google DAI API key. - Instantiate an
ImaDaiSettings
object. In our code example, we name thisimaDaiSettings
. - If you have custom ad tag parameters, add them to the settings object with the
setAdTagParameters()
method. - Add the
ImaDaiSettings
object to theimaDaiSettings
property of thePlaylistItem
object.
mPlayerView = findViewById(R.id.jwplayer);
String cmsId = "CMS_ID";
String videoId = "VIDEO_ID";
// apiKey can be null
String apiKey = "YOUR_API_KEY";
boolean isDash = false;
ImaDaiSettings imaDaiSettings = new ImaDaiSettings(cmsId, videoId, isDash, 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();
playlist.add(playlistItem);
PlayerConfig config = new PlayerConfig.Builder()
.playlist(playlist)
.build();
mPlayerView.setup(config);
mPlayerView = findViewById(R.id.jwplayer);
String assetKey = "ASSET_KEY_ID";
String apiKey = "YOUR_API_KEY";
boolean isDash = false;
ImaDaiSettings imaDaiSettings = new ImaDaiSettings(assetKey, isDash, apiKey);
// 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();
mPlayerView.setup(config);
Updated about a month ago