This article introduces two additions to Brightcove's Advertising APIs:
One of the features that developers have requested the most is a way to detect when all post-roll ads have completed, either when the ad completes or even when no ad is returned. Until now, there was not an easy way to detect when the process of requesting and playing post-rolls was done. If you know this, you can know precisely when you can continue with a new action after all advertising activity is complete for a video.
For example, let's say that you have built a custom playlist external to the Brightcove Player and you want to add auto-advance in that playlist using the Brightcove Player APIs. You would probably add a listener to the AD_COMPLETE event, and check the current ad insertion point to detect if the ad that just completed was a post-roll ad, and then call the VideoPlayer.loadMedia() API to load the next video on the list. However, what happens when the post-roll requests do not return an ad (which could happen if there was no more ad inventory, etc.)? Since no ad is rendered, the AD_COMPLETE event does not fire, and your auto-advance would stop working.
To handle this situation, we have added a new event to the Advertising API module that will allow developers to detect when all post-roll activity is complete. The new event is named AD_POSTROLLS_COMPLETE and it is part of the Advertising API.
You use this event just like other existing ad events. First, get a reference to the Ad Module API and then add an event listener to the AD_POSTROLLS_COMPLETE event. For example:
function onTemplateLoaded(pExperience) {
player= brightcove.getExperience(pExperience);
adModule = player.getModule(APIModules.ADVERTISING);
adModule.addEventListener(BCAdvertisingEvent.AD_POSTROLLS_COMPLETE, onPostRollsComplete);
}
function onPostRollsComplete(evt){
// Do something, like load a new video
}
To use this event effectively, you need to understand when this event is fired. Here is a list of scenarios and sequences where this event is fired:
Yes. The AD_POSTROLLS_COMPLETE event will fire after the adComplete() method is called on an Ad Display SWF or, in the case of Ad Rules, also after the postrollCheckComplete() method is called and no ad is being played. These two scenarios would be similar to cases 1 and 2 above, respectively.
Another popular request, one which correlates with the use cases in this article, is for an API that would reliably tell if a player is enabled for ads or not. An existing method, getAdPolicy(), can be used to check for the ad policy and then evaluate if ads were on or off in a player. However, the new getAdEnabled() API is more straightforward. You can use it together with AD_POSTROLLS_COMPLETE when you need to detect when all activity after a video completes is done; it works both for players that are ad enabled and also for players that are not ad enabled.
For example, suppose you want to create code that you can re-use no matter what ad settings are set for a player and you want to detect when the video is complete (including advertising when the ads are enabled). In other words, when ads are enabled you want to continue with your video-complete logic after post-roll activity is complete and when ads are off you want to continue when the video completes, since you know that no ads will be requested. This is where getAdEnabled() helps the most. The solution would be something like this:
For example:
function onTemplateLoaded(pExperience) {
player= brightcove.getExperience(pExperience);
modExp = player.getModule(APIModules.EXPERIENCE);
modVP = player.getModule(APIModules.VIDEO_PLAYER);
adModule = player.getModule(APIModules.ADVERTISING);
var isAdEnabled = modExp.getAdEnabled();
if (isAdEnabled) {
adModule.addEventListener(BCAdvertisingEvent.AD_POSTROLLS_COMPLETE,
onVideoEventsComplete);
} else {
modVP.addEventListener(BCMediaEvent.COMPLETE, onVideoEventsComplete);
}
}
function onVideoEventsComplete(evt){
// Do something, like loading a new video.
}
We look forward to your implementations using these two new additions to Brightcove's advertising related APIs. Please do not hesitate to follow up with any questions in our Ad API forum.