Schedule FreeWheel ads (Android v3)

Schedule ads with the FreeWheel Ad Manager ad client in an Android app.


After adding the FreeWheel Ad Manager to your app and acquiring the required items listed in the Requirements section, you can schedule FreeWheel ads in your Android app.


Requirements

PropertyDescriptionExample
mediaIdFreeWheel identifier of a particular media itemfw_simple_tutorial_asset
networkIdFreeWheel identifier of a network42015
profileIdFreeWheel identifier of a particular application environmentfw_tutorial_android
sectionIdFreeWheel identifier of a location where the video content playsfw_tutorial_android
serverIdURL of FreeWheel ad serverhttp://7cee0.v.fwmrm.net/

If you do not know where to find the FreeWheel account values in the table, contact your FreeWheel account representative.



Add a single ad break for all playlist items

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

  1. In app/java/MainActivity.java, define your FW account values: networkId, serverId, profileId, sectionId, and mediaId.
  2. Create a FwSettings object and name it, for example, called settings. Add your FW account settings to this object.
  3. Create a List<AdBreak> object and name it, for example, adSchedule.
  4. Create an AdBreak object and name it, for example, adBreak. At the minimum, you must pass an ad tag placeholder to the tag property and pass AdSource.FW to the source property.
  5. Add adBreak to adSchedule.
  6. Create a FwAdvertising object and name it, for example, advertising. Use settings and adSchedule as the arguments. The settings object defines the FreeWheel Ad Manager settings. The adSchedule object defines which ad schedule to use.
  7. Add advertising(advertising) to the config object of the player. This adds the ad schedule to the player.
mPlayerView = findViewById(R.id.jwplayer);

int networkId = {freewheel_network_id};
String serverId = "{freewheel_server_id}";
String profileId = "{freewheel_profile_id}";
String sectionId = "{freewheel_section_id}";
String mediaId = "{freewheel_media_id}";
FwSettings settings = new FwSettings(networkId, serverId, profileId, sectionId, mediaId);

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

AdBreak adBreak = new AdBreak.Builder()
    .tag("fw_preroll")
    .source(AdSource.FW)
    .build();
        
adSchedule.add(adBreak);

FwAdvertising advertising = new FwAdvertising(settings, 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(advertising)
    .build();

mPlayerView.setup(config);

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



Add multiple ad breaks for all playlist items

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

  1. Define an additional AdBreak object.
  2. Define the object's offset property. When defining the offset property, choose one of the following values to schedule a mid-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.

  3. Pass AdSource.FW to the source property.
  4. Add the additional AdBreak object to adSchedule.

In the code examples below, we have added three additional ad breaks: adBreak2, adBreak3, adBreak4.

mPlayerView = findViewById(R.id.jwplayer);

int networkId = {freewheel_network_id};
String serverId = "{freewheel_server_id}";
String profileId = "{freewheel_profile_id}";
String sectionId = "{freewheel_section_id}";
String mediaId = "{freewheel_media_id}";
FwSettings settings = new FwSettings(networkId, serverId, profileId, sectionId, mediaId);

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

AdBreak adBreak = new AdBreak.Builder()
    .tag("fw_preroll")
    .offset("pre")
    .source(AdSource.FW)
    .build();

AdBreak adBreak2 = new AdBreak.Builder()
    .tag("fw-midroll1")
    .offset("10")
    .source(AdSource.FW)
    .build();

AdBreak adBreak3 = new AdBreak.Builder()
    .tag("fw-midroll2")
    .offset("00:00:15:000")
    .source(AdSource.FW)
    .build();

AdBreak adBreak4 = new AdBreak.Builder()
    .tag("fw-midroll3")
    .offset("25%")
    .source(AdSource.FW)
    .build();
        
adSchedule.add(adBreak);
adSchedule.add(adBreak2);
adSchedule.add(adBreak3);
adSchedule.add(adBreak4);

FwAdvertising advertising = new FwAdvertising(settings, 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(advertising)
    .build();

mPlayerView.setup(config);


Specify ad content for a specific playlist item

Use the following steps to specify advertising content for a specific playlist item. If you do not apply these steps to a playlist item, the default FreeWheel advertising content will play.

  1. For a specific playlist item, create a PlaylistItem. In our code example, we name this object playlistItem2.
  2. Define the freewheelSettings property with the FreeWheel settings for the advertising content. This associates the specific FreeWheel advertising content to the PlaylistItem.
mPlayerView = findViewById(R.id.jwplayer);

int networkId = {freewheel_network_id};
String serverId = "{freewheel_server_id}";
String profileId = "{freewheel_profile_id}";
String sectionId = "{freewheel_section_id}";
String mediaId = "{freewheel_media_id}";
FwSettings settings = new FwSettings(networkId, serverId, profileId, sectionId, mediaId);

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

AdBreak adBreak = new AdBreak.Builder()
    .tag("fw_preroll")
    .offset("pre")
    .source(AdSource.FW)
    .build();

AdBreak adBreak2 = new AdBreak.Builder()
    .tag("fw-midroll1")
    .offset("10")
    .source(AdSource.FW)
    .build();

AdBreak adBreak3 = new AdBreak.Builder()
    .tag("fw-midroll2")
    .offset("00:00:15:000")
    .source(AdSource.FW)
    .build();

AdBreak adBreak4 = new AdBreak.Builder()
    .tag("fw-midroll3")
    .offset("25%")
    .source(AdSource.FW)
    .build();
        
adSchedule.add(adBreak);
adSchedule.add(adBreak2);
adSchedule.add(adBreak3);
adSchedule.add(adBreak4);

FwAdvertising advertising = new FwAdvertising(settings, adSchedule);

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

PlaylistItem playlistItem2 = new PlaylistItem.Builder()
    .file("https://cdn.jwplayer.com/manifests/{media_id2}.m3u8")
    .freewheelSettings(new FwSettings {freewheel_network_id}, {freewheel_server_id}, {freewheel_profile_id}, {freewheel_section_id}, {freewheel_media_id}) 
    .build();

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

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

mPlayerView.setup(config);