Schedule Google IMA ads

Add advertising breaks to your content when using the Google IMA ad client in an Android app.


After adding the Google IMA SDK to your app and acquiring the required items listed in the Requirements section, you can schedule Google IMA ads in your Android app.


Requirements



Add a pre-roll ad to a playlist

👍

IMPORTANT

If you use the IAB Open Measurement Interface Definition (OMID) and run Google IMA ads, all custom video controls that overlay the media element must be registered as friendly obstructions.


Use the following steps to add a pre-roll ad to the player you added to your activity:

  1. In app/java/MainActivity.java, create a List<AdBreak> object and name it, for example, adSchedule.
  2. Create an AdBreak object and name it, for example, adBreak. At the minimum, you must pass an ad tag to the tag property. We strongly recommend using a secure ad tag URL.
  3. Add adBreak to adSchedule.
  4. Create an ImaAdvertising object and name it, for example, imaAdvertising. Use adSchedule (which defines the ad schedule to use) as the argument.
  5. Add advertising(imaAdvertising) to the config object of the player. This adds the ad schedule to the player.
mPlayerView = findViewById(R.id.jwplayer);

List<AdBreak> adSchedule = new ArrayList<>();

AdBreak adBreak = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag.xml")
    .offset("pre")
    .build();
        
adSchedule.add(adBreak);

ImaAdvertising imaAdvertising = new ImaAdvertising(adSchedule);

PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://cdn.jwplayer.com/manifests/{media_id}.m3u8")
    .build();

List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);

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

mPlayerView.setup(config);

You can build upon this basic implementation by adding multiple ad breaks.



Add multiple ad breaks to a player

👍

IMPORTANT

If you use the IAB Open Measurement Interface Definition (OMID) and run Google IMA ads, all custom video controls that overlay the media element must be registered as friendly obstructions.


Use the following steps to add multiple ad breaks to the previous VAST pre-roll example:

  1. Define an additional AdBreak object.
  2. Pass an ad tag to the tag property.
  3. When defining the offset property, choose one of the following values to schedule a mid-roll or post-roll ad.

    Mid-roll
      - {number}: (String) Ad plays after the specified number of seconds.
      - {timecode}: (String) Ad plays at a specific time, in hh:mm:ss:mmm format.

    Post-roll
      - post: (String) Ad plays after the content.

  4. Add the additional AdBreak object to adSchedule.
mPlayerView = findViewById(R.id.jwplayer);

List<AdBreak> adSchedule = new ArrayList<>();

AdBreak adBreak = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag.xml")
    .offset("pre")
    .build();

AdBreak adBreak2 = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag-mid-roll1.xml")
    .offset("10")
    .build();

AdBreak adBreak3 = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag-mid-roll2.xml")
    .offset("00:00:15:000")
    .build();

AdBreak adBreak4 = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag-mid-roll3.xml")
    .offset("25%")
    .build();

AdBreak adBreak5 = new AdBreak.Builder()
    .tag("https://www.domain.com/adtag-post-roll.xml")
    .offset("post")
    .build();
        
adSchedule.add(adBreak);
adSchedule.add(adBreak2);
adSchedule.add(adBreak3);
adSchedule.add(adBreak4);
adSchedule.add(adBreak5);

ImaAdvertising imaAdvertising = new ImaAdvertising(adSchedule);

PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://cdn.jwplayer.com/manifests/{media_id}.m3u8")
    .build();

List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);

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

mPlayerView.setup(config);


Did this page help you?