Ad options
All methods are defined in the StreamingSession
class.
- Follow Setup ad insertion
- A player that supports ad tracking
Activate advertising
Activate the advertising workflow (ad session creation, ad tracking and ad analytics).
The method setAdParameter
automatically calls this method.
- Android
- iOS & tvOS
- Web
/**
* Activate advertising workflow (including analytics and tracking)
* The method setAdParameter automatically calls this method
*/
session.activateAdvertising();
/**
* Activate advertising workflow (including analytics and tracking)
* The method setAdParameter automatically calls this method
*/
[session activateAdvertising];
/**
* Activate advertising workflow (including analytics and tracking)
* The method setAdParameter automatically calls this method
*/
session.activateAdvertising();
The method has to be called before starting the session (i.e calling getURL
).
Set ad parameter
Set a parameter used for the ad insertion. They are sent to the BkYou and the ad provider to generate a more personalized ad insertion.
- Android
- iOS & tvOS
- Web
/**
* This method set a parameter used for the ad insertion
* @param name Parameter name
* @param value Parameter value
*/
session.setAdParameter("name", "value");
/**
* This method set a parameter used for the ad insertion
* @param name Parameter name
* @param value Parameter value
*/
[session setAdParameter:@"name" value:@"value"];
/**
* This method set a parameter used for the ad insertion
* @param name Parameter name
* @param value Parameter value
*/
session.setAdParameter("name", "value");
The method has to be called before starting the session (i.e calling getURL
).
Ad user interaction
Trigger an ad user interaction to report the ad click tracker. It is mandatory for a Google integration through the PAL SDK or for a OM SDK integration.
The method can be called anytime during a running session.
- Android
- iOS & tvOS
- Web
/**
* Trigger an ad user interaction (OMSDK, PAL SDK)
* @param interactionType see AdInteractionType class to get types
*/
session.adUserInteraction(AdInteractionType.CLICK);
public class AdInteractionType {
/**
* Ad user click interaction type
*/
public static final String CLICK = "click";
/**
* Ad user invitation accept interaction type
*/
public static final String INVITATION_ACCEPTED = "invitationAccept";
}
/**
* Trigger an ad user interaction (OMSDK, PAL SDK)
* @param interactionType see BPAdInteractionType constants to get types
*/
[session adUserInteraction:BPAdInteractionTypeClick];
/**
* Ad user click interaction type
*/
#define BPAdInteractionTypeClick @"click"
/**
* Ad user invitation accept interaction type
*/
#define BPAdInteractionTypeInvitationAccepted @"invitationAccept"
/**
* Trigger an ad user interaction (OMSDK, PAL SDK)
* @param interactionType 'click' or 'invitationAccept'
*/
session.adUserInteraction('click');
Ad data
The ad data model can be retrieved through listeners (ad events listener or ad data listener) or methods (get ad list, get current ad break or get current ad).
AdBreakData
This object contains all info about an ad break, including the ad list.
In case of live content:
- The duration is set to -1
- The ad count is set to -1
- Android
- iOS & tvOS
- Web
/**
* Ad break data
* Returned by session.getAdList()
*/
class AdBreakData {
/**
* Ad break id
*/
String getId();
/**
* Start position in millis
*/
long getStartPosition();
/**
* Duration in millis
* Includes all ads
*/
long getDuration();
/**
* Ad list
*/
ArrayList<AdData> getAds();
/**
* Total ad count
* If live content, adCount will be -1
*/
int getAdCount();
}
@interface AdBreakData : NSObject
/**
* Ad break id
*/
@property (nonatomic,strong) NSString *adBreakId;
/**
* Start position in millis
*/
@property (nonatomic,assign) long startPosition;
/**
* Duration in millis
* Includes all ads
*/
@property (nonatomic,assign) long duration;
/**
* Ad list
*/
@property (nonatomic,strong) NSMutableArray<AdData *> *ads;
/**
* Total ad count
* If live content, adCount will be -1
*/
@property (nonatomic,assign) int adCount;
@end
{
id: 'adBreakId-midroll', // Ad break id
startPosition: 30000, // Start position in millis
duration: 20000, // Duration in millis, includes all ads
adCount: 1, // Total ad count. If live content, adCount will be -1
ads: [ // Ad list
...
]
}
AdData
This object contains all info about an ad.
- Android
- iOS & tvOS
- Web
class AdData {
/**
* Ad index in the ad break
*/
public int getIndex();
/**
* Ad creative id
*/
String getCreativeId();
/**
* Ad id
* If the same ad is played in the content, the id will be the same
*/
String getAdId();
/**
* Start position in millis
*/
long getStartPosition();
/**
* Skip position in millis
* 0 if not defined
*/
long getSkipPosition();
/**
* Duration in millis
*/
long getDuration();
/**
* Click URL
* Empty string if not defined
*/
String getClickURL();
}
@interface AdData : NSObject
/**
* Ad index in the ad break
*/
@property (nonatomic,assign) int index;
/**
* Ad creative id
*/
@property (nonatomic,strong) NSString *creativeId;
/**
* Ad id
* If the same ad is played in the content, the id will be the same
*/
@property (nonatomic,strong) NSString *adId;
/**
* Start position in millis
*/
@property (nonatomic,assign) long startPosition;
/**
* Skip position in millis
* 0 if not defined
*/
@property (nonatomic,assign) long skipPosition;
/**
* Duration in millis
*/
@property (nonatomic,assign) long duration;
/*
* Click URL
* Empty string if not defined
*/
@property (nonatomic,assign) NSString *clickURL;
@end
{
index: 0, // Ad index in the ad break
creativeId: 'adCreativeId', // Ad creative id
adId: 'adId', // Ad id
startPosition: 30000, // Start position in millis
skipPosition: 35000, // Skip position in millis, 0 if not defined
duration: 10000, // Duration in millis
clickURL: 'https://ad.tv' // Click URL, empty string if not defined
}
Listen to ad events
This method allows the app to listen to ad events:
- when an ad break begins,
onAdBreakBegin
is triggered - when an ad break ends,
onAdBreakEnd
is triggered - when an ad begins,
onAdBegin
is triggered - when an ad ends,
onAdEnd
is triggered - if an ad is skippable,
onAdSkippable
is triggered afteronAdBegin
with skip begin position, current ad end position and ad break end position. This allows to skip either the current ad or all ads in ad break.
It can be used to interact with the UI, for instance to lock player controls during an ad or show a skip button.
The placement of the ad break can be computed:
- pre-roll: the ad break position is equal to 0
- post-roll: the ad break end position (ad break position + ad break duration) is greater than the content duration - 1 second
- mid-roll: all other cases
Find more details about AdData
and AdBreakData
in Ad options.
Since the version 04.06.02, modifications have been made to the arguments of the ad events listener. Please update your code if needed.
Here are the modifications that have been implemented:
position
➡adBreakData.startPosition
oradData.startPosition
duration
➡adBreakData.duration
oradData.duration
clickURL
➡adData.clickURL
sequenceNumber
➡adData.index
totalNumber
➡adBreakData.adCount
- Android
- iOS & tvOS
- Web
session.setAdEventsListener(new AdManager.AdEventsListener() {
/**
* Triggered when ad breaks begin
* @param adBreak Ad break data
*/
void onAdBreakBegin(AdBreakData adBreak) {
// Lock player controls
}
/**
* Triggered when an ad begin
* @param adData Ad data
* @param adBreakData Ad break data
*/
void onAdBegin(AdData adData, AdBreakData adBreakData) {
// Show ad link button if needed
}
/**
* Triggered when an ad is skippable
* @param adData Ad data
* @param adBreakData Ad break data
* @param adSkippablePosition position in millis where skip becomes allowed
* @param adEndPosition position in millis of ad end
* @param adBreakEndPosition position in millis of ad break end
*/
void onAdSkippable(AdData adData, AdBreakData adBreakData, long adSkippablePosition, long adEndPosition, long adBreakEndPosition) {
// Show the skip message/button "skip ad in x seconds"
}
/**
* Triggered when the ad is ended, not called if skipped
* @param adData Ad data
* @param adBreakData Ad break data
*/
void onAdEnd(AdData adData, AdBreakData adBreakData) {
// Hide ad link, hide ad skip button
}
/**
* Triggered when ad breaks ended, even in case of skipping
* @param adBreakData Ad break data
*/
void onAdBreakEnd(AdBreakData adBreakData) {
// Unlock player controls, hide ad link, hide ad skip button
}
});
// Registering to ad events
[session setAdEventsListener:self];
/**
* Triggered when ad breaks begin
* @param adBreak Ad break data
*/
- (void)onAdBreakBegin:(AdBreakData *)adBreak {
// Lock player controls
}
/**
* Triggered when an ad begin
* @param adData Ad data
* @param adBreakData Ad break data
*/
- (void)onAdBegin:(AdData *)adData adBreakData:(AdBreakData *)adBreakData {
// Show ad link button if needed
}
/**
* Triggered when an ad is skippable
* @param adData Ad data
* @param adBreakData Ad break data
* @param adSkippablePosition position in millis where skip becomes allowed
* @param adEndPosition position in millis of ad end
* @param adBreakEndPosition position in millis of ad break end
*/
- (void)onAdSkippable:(AdData *)adData adBreakData:(AdBreakData *)adBreakData adSkippablePosition:(long)adSkippablePosition adEndPosition:(long)adEndPosition adBreakEndPosition:(long)adBreakEndPosition {
// Show the skip message/button "skip ad in x seconds"
}
/**
* Triggered when the ad is ended, not called if skipped
* @param adData Ad data
* @param adBreakData Ad break data
*/
- (void)onAdEnd:(AdData *)adData adBreakData:(AdBreakData *)adBreakData {
// Hide ad link, hide ad skip button
}
/**
* Triggered when ad breaks ended, even in case of skipping
* @param adBreakData Ad break data
*/
- (void)onAdBreakEnd:(AdBreakData *)adBreakData {
// Unlock player controls, hide ad link, hide ad skip button
}
session.setAdEventsListener({
/**
* Triggered when an ad break begin
* @param adBreakData Ad break data
*/
onAdBreakBegin: (adBreakData) => {
// Lock player controls
},
/**
* Triggered when an ad begin
* @param adData Ad data
* @param adBreakData Ad break data
*/
onAdBegin: (adData, adBreakData) => {
// Show ad link button if needed
},
/**
* Triggered when an ad is skippable
* @param adData Ad data
* @param adBreakData Ad break data
* @param adSkippablePosition position in millis where skip becomes allowed
* @param adEndPosition position in millis of ad end
* @param adBreakEndPosition position in millis of ad break end
*/
onAdSkippable: (adData, adBreakData, adSkippablePosition, adEndPosition, adBreakEndPosition) => {
// Show the skip message/button "skip ad in x seconds"
},
/**
* Triggered when the ad is ended, not called if skipped
* @param adData Ad data
* @param adBreakData Ad break data
*/
onAdEnd: (adData, adBreakData) => {
// Hide ad link, hide ad skip button
},
/**
* Triggered when ad break ended, even in case of skipping
* @param adBreakData Ad break data
*/
onAdBreakEnd: (adBreakData) => {
// Unlock player controls, hide ad link, hide ad skip button
}
});
The method has to be called before starting the session (i.e calling getURL
).
Listen to ad data
This method allows the app to listen to ad data. It returns the ad list and allow the app to perform specifics ad behavior (Restore a bookmark position).
The event is triggered:
- during
getURL
with the ad list - during the playback everytime the ad list is updated
- Android
- iOS & tvOS
- Web
session.setAdDataListener(new AdManager.AdDataListener() {
/**
* Triggered when ad data have been received during getURL
* @param adList list of ad breaks
*/
@Override
public void onAdData(ArrayList<AdBreakData> adList) {
}
});
// Registering to ad data
[session setAdDataListener:self];
/**
* Triggered when ad data have been received during getURL
* @param adList list of ad breaks
*/
- (void)onAdData:(nonnull NSArray<AdBreakData *> *)adList {
}
session.setAdDataListener({
/**
* Triggered when ad data have been received during getURL
* @param adList list of ad breaks
*/
onAdData: adList => {
}
});
The method has to be called before starting the session (i.e calling getURL
).
When registering to this listener, the BkYou will request the ad provider during the getURL
processing instead of during the manifest retrieving by the player.
It will slightly increase the redirection time (time between the start of getURL
and the end).
However, the startup time (time between the start of getURL
and the first image displayed) will not change.
Get ad list
This method returns the ad break list. Each ad breaks contain a list of ads.
If the ad break list has not already been received, the method returns an empty array.
To ensure that the function will return the correct result, call it once onAdData
has been triggered (see Listen to ad data).
After the data has been removed from the BkYou tracking file, it remains in memory until the end of the ad break playback.
- Android
- iOS & tvOS
- Web
/**
* Return the current ad list
* It can be called after or inside onAdData event
* @return list of ad breaks
*/
ArrayList<AdBreakData> list = session.getAdList();
/**
* Return the current ad list
* It can be called after or inside onAdData event
* @return list of ad breaks
*/
NSArray<AdBreakData *> *list = [session getAdList];
/**
* Return the current ad list
* It can be called after or inside onAdData event
* @returns list of ad breaks
*/
const list = session.getAdList();
Get current ad break
This method returns the current ad break. Each ad breaks contain a list of ads.
If the player is not playing an ad break, the method returns null.
- Android
- iOS & tvOS
- Web
/**
* Return the current ad break
* @return current ad break or null
*/
AdBreakData adBreakData = session.getCurrentAdBreak();
/**
* Return the current ad break
* @return current ad break or nil
*/
AdBreakData *adBreakData = [session getCurrentAdBreak];
/**
* Return the current ad break
* @returns {*} current ad break or undefined
*/
const adBreakData = session.getCurrentAdBreak();
Get current ad
This method returns the current ad.
If the player is not playing an ad, the method returns null.
- Android
- iOS & tvOS
- Web
/**
* Return the current ad
* @return current ad or null
*/
AdData adData = session.getCurrentAd();
/**
* Return the current ad
* @return current ad or nil
*/
AdData *adBreakData = [session getCurrentAd];
/**
* Return the current ad
* @returns {*} current ad or undefined
*/
const ad = session.getCurrentAd();
Create a bookmark position
This method returns a bookmark position to store in the application. It takes into account the current position and ads in the content. It will avoid restoring the position on the same content later at an incorrect position (ads can move into the content or can be deleted).
Check the sample code to see a bookmarking implementation.
- Android
- iOS & tvOS
- Web
/**
* Return the current position within the content without ads
* This position can be saved to be restored later through getPositionForPlayback(positionInBookmark, beforeAdBreak)
* For VOD contents only
*
* @return Position in milliseconds in the content without ads
*/
long position = session.getPositionForBookmark();
/**
* Return the current position within the content without ads
* This position can be saved to be restored later through getPositionForPlayback(positionInBookmark, beforeAdBreak)
* For VOD contents only
*
* @return Position in milliseconds in the content without ads
*/
long position = [session getPositionForBookmark];
/**
* Return the current position within the content without ads
* This position can be saved to be restored later through getPositionForPlayback(positionInBookmark, beforeAdBreak)
* For VOD contents only
*
* @returns {number} Position in milliseconds in the content without ads
*/
const position = session.getPositionForBookmark();
Restore a bookmark position
This method returns a playback position based on a bookmarked position. It takes into account current ads in the content.
To ensure that the function will return the correct result, call it once onAdData
has been triggered (see Listen to ad data).
Check the sample code to see a bookmarking implementation.
- Android
- iOS & tvOS
- Web
/**
* Return the position including current ads with the position in the content without ads
* Can be called after or inside onAdData
* For VOD contents only
*
* @param positionInBookmark position in milliseconds in the content without ad (with the stored value got from the method getPositionForBookmark())
* @param beforeAdBreak if set to true, return position before ad break (false by default)
* @return Position including current ads in milliseconds
*/
long position = session.getPositionForPlayback(positionInBookmark, beforeAdBreak);
/**
* Return the position including current ads with the position in the content without ads
* Can be called after or inside onAdData
* For VOD contents only
*
* @param positionInBookmark position in milliseconds in the content without ad (with the stored value got from the method getPositionForBookmark())
* @param beforeAdBreak if set to true, return position before ad break (false by default)
* @return Position including current ads in milliseconds
*/
long position = [session getPositionForPlayback:positionInBookmark beforeAdBreak:beforeAdBreak];
/**
* Return the position including current ads with the position in the content without ads
* Can be called after or inside onAdData
* For VOD contents only
*
* @param positionInBookmark position in milliseconds in the content without ad (with the stored value got from the method getPositionForBookmark())
* @param beforeAdBreak if set to true, return position before ad break (false by default)
* @returns {number} Position including current ads in milliseconds
*/
const position = session.getPositionForPlayback(positionInBookmark, beforeAdBreak);
Set a user agent for ad tracking events
This method allows to the app to set the user agent used by the SmartLib during ad tracking event HTTP requests. It overrides the custom user agent if it has been set.
- Android
- iOS & tvOS
- Web
// Per session setting
session.setOption(StreamingSessionOptions.USERAGENT_AD_EVENT, "useragent");
// Per session setting
[session setOption:SMARTLIB_USERAGENT_AD_EVENT valueWithString:@"useragent"];
// Per session setting
session.setOption(StreamingSessionOptions.USERAGENT_AD_EVENT, "useragent");
The method has to be called before starting the session (i.e calling getURL
).