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
- All the JWP Android SDK requirements
- Android SDK advertising requirements
- FreeWheel Ad Manager
- All FreeWheel account information listed in the following table
Property | Description | Example |
---|---|---|
mediaId | FreeWheel identifier of a particular media item | fw_simple_tutorial_asset |
networkId | FreeWheel identifier of a network | 42015 |
profileId | FreeWheel identifier of a particular application environment | fw_tutorial_android |
sectionId | FreeWheel identifier of a location where the video content plays | fw_tutorial_android |
serverId | URL of FreeWheel ad server | http://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:
- In app/java/MainActivity.java, define your FW account values:
networkId
,serverId
,profileId
,sectionId
, andmediaId
. - Create a
FwSettings
object and name it, for example, calledsettings
. Add your FW account settings to this object. - Create a
List<AdBreak>
object and name it, for example,adSchedule
. - Create an
AdBreak
object and name it, for example,adBreak
. At the minimum, you must pass an ad tag placeholder to thetag
property and passAdSource.FW
to thesource
property. - Add
adBreak
toadSchedule
. - Create a
FwAdvertising
object and name it, for example,advertising
. Usesettings
andadSchedule
as the arguments. Thesettings
object defines the FreeWheel Ad Manager settings. TheadSchedule
object defines which ad schedule to use. - Add
advertising(advertising)
to theconfig
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:
- Define an additional
AdBreak
object. - 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, inhh:mm:ss:mmm
format.
Post-roll
Β Β -post
: (String) Ad plays after the content. - Pass
AdSource.FW
to thesource
property. - Add the additional
AdBreak
object toadSchedule
.
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.
- For a specific playlist item, create a
PlaylistItem
. In our code example, we name this objectplaylistItem2
. - Define the
freewheelSettings
property with the FreeWheel settings for the advertising content. This associates the specific FreeWheel advertising content to thePlaylistItem
.
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);
Updated over 1 year ago