Display banner ads

Displaying banner ads involves creating banner instances and listening for ad-related events.

The PSDK provides a list of companion banner ads associated with a linear ad through the PTMediaPlayerAdPlayStartedNotification notification.

Manifests can specify companion banner ads as three possible types:
  • By an HTML snippet
  • By a URL to an iFrame page
  • By a URL to a static image or an Adobe Flash SWF file

For each companion ad, the PSDK indicates which type or types are available for your application to use.

  1. Create a PTAdBannerView instance for each companion ad slot on your page. The banner instance should specify width and height to prevent retrieval of companions of different sizes. Specify standard banner sizes.
  2. Add an observer for the PTMediaPlayerAdStartedNotification that does the following:
    1. Clear any previously existing ads in the banner instance.
    2. Get the list of companion ads from PTAd.companionAssets.
    3. If the list of companion ads is not empty, iterate over the list for banner instances.

      Each banner instance (a PTAdAsset) contains information necessary for displaying the companion banner, such as width, height, resource type (html, iframe, or static), and data.

    4. If a video ad has no companion ads booked with it, then the list of companion assets will contain no data for that video ad. In this case, if you want to show a standalone display ad, add the logic to your script to run a normal DFP display ad tag in the appropriate banner instance.
    5. Send the banner information to a function on your page that displays the banners in an appropriate location.

      This is usually a div, and your function uses the div ID to display the banner.

For example:

- (void) onMediaPlayerAdPlayStarted:(NSNotification *) notification {
    _currentAd  = [notification.userInfo  objectForKey:PTMediaPlayerAdKey]; 
    if (_currentAd != nil) {
        [self removeAllBanners]; // remove any existing PTAdBannerView views

        // banners
        if (_currentAd.companionAssets && _currentAd.companionAssets.count > 0) {
            PTAdAsset *bannerAsset = [_currentAd.companionAssets objectAtIndex:0];

            PTAdBannerView *bannerView = [[PTAdBannerView alloc] initWithAsset:bannerAsset]; 
            bannerView.player = self.player;
            bannerView.delegate = self;

            bannerView.frame = CGRectMake(0.0, 0.0, bannerAsset.width, bannerAsset.height); 
            [_adBannerView.bannerView addSubview:bannerView];
        }
    }
}