Define ad rules

Last Updated: June 13, 2019

After adding ads to your content, you can define ad rules that control how often a viewer sees ads while viewing your video content. Ad rules can be used only when using a VAST (AdSource.VAST) ad client.

  • If you are publishing playlists that consist of short-duration videos, like tutorials or product reviews, you can define startOn (the first playlist item allowing ad playback) and frequency (the regularity of ads within a playlist).
  • If you are publishing long-form content, like webinars or interviews, you can define startOnSeek (which determines if a returning visitor is served a pre-roll before resuming content playback) and timeBetweenAds (which sets the minimum time that must elapse between ads playback).

You can read Ad rules reference to learn more about how each ad rule impacts a user's experience.


Implementation

Use the following steps and code samples to define ad rules for the player your added to your activity with an ad schedule.

  1. Create an AdRules object named adRules.
  2. Configure the properties of the adRules object for your use case.
  3. Add adRules to adSchedule.


Examples

Example 1: Short-form content

The following example illustrates a short-form media item with a pre-roll. The first ad plays before the first playlist item (startOn: 1). Then, subsequent pre-rolls appear for every third playlist item (frequency: 3), starting with the fourth playlist item.

mPlayerView = findViewById(R.id.jwplayer);

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

AdBreak adBreak = new AdBreak.Builder()
    .tag("//playertest.longtailvideo.com/pre.xml")
    .offset("pre")
    .build();

adSchedule.add(adBreak);

Advertising advertising = new Advertising(AdSource.VAST, adSchedule);
AdRules adRules = new AdRules.Builder()
    .startOn(1)
    .frequency(3)
    .build();
advertising.setAdRules(adRules);

PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://content.jwplatform.com/videos/123acb4e-Zy98xW76.mp4")
    .mediaId("123acb4e")
    .build();

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


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

mPlayerView.setup(config);

Example 2: Long-form content

The following example illustrates a long-form media item with multiple ad breaks. The startOnSeek and timeBetweenAds (set to 300 seconds) ad rules have been defined.

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);

Advertising advertising = new Advertising(AdSource.VAST, adSchedule);
AdRules adRules = new AdRules.Builder()
    .startOnSeek("pre")
    .timeBetweenAds(300)
    .build();
advertising.setAdRules(adRules);

PlaylistItem playlistItem = new PlaylistItem.Builder()
    .file("https://content.jwplatform.com/videos/123acb4e-Zy98xW76.mp4")
    .mediaId("123acb4e")
    .build();

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


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

mPlayerView.setup(config);



Use this form to provide your feedback.