Ads

Google IMA

Google IMA SDKs make it easy to integrate multimedia ads into your websites and apps. IMA SDKs can request ads from any VAST-compliant ad server and manage ad playback in your apps. With IMA client-side SDKs, you maintain control of content video playback, while the SDK handles ad playback. Ads play in a separate video player positioned on top of the app’s content video player.

CastlabsIMA integrates the Google SDK into our player, handles automatically the required callbacks, and simplifies the public API.

The Google IMA SDK provides the tools to integrate and manage video ads in your app. PRESTOplay SDK simplifies displaying ads by providing an interface to the Google IMA SDK, making it easy to incorporate and control ads in your application.

Integrate

Include the GoogleAds-IMA-iOS-SDK library in your project. Here is an example using CocoaPods:

pod 'GoogleAds-IMA-iOS-SDK'

Register the IMA plugin to PRESTOplay SDK:

import PRESTOplay
import CastlabsIMA

...

PRESTOplaySDK.shared.register("LICENSE", [IMAPlugin()])

Scheduling Ads

In your view controller, you can schedule ads as follows:

override func viewDidAppear(_ animated: Bool) {
    ...
    let ads = PRESTOplaySDK.shared.ads(for: player)
    let url = URL(string: "https://players.castlabs.com/ads/vmap?ad=1,start&ad=00:01:15&ad=1,end")!
    ads?.requestAds(withUrl: url, onView: view, viewController: self)
}

Note: Since the Google IMA SDK requires the ad container to be in the view hierarchy, the requestAds() method should be called within the viewDidAppear() event.

Please check our examples/IMADemo for complete implementation.

Ads Events

Clients can receive ad events through the AdsAPI.onAdsState closure.

var player = PRESTOplaySDK.shared.player()
var ads = PRESTOplaySDK.shared.ads(for: player)
ads?.onAdsState = { state in
    switch state.adsEvent?.type {
    case .started:
        print("Ad started")
    case .complete:
        print("Ad complete")
    case .allAdsCompleted:
        print("All Ads complete")
    default:
        print("\(state.adsEvent?.type)")
    }
}

More information

iOS targets: https://developers.google.com/interactive-media-ads/docs/sdks/ios/download

tvOS targets: https://developers.google.com/interactive-media-ads/docs/sdks/tvos/download

More details on how to start wih Google IMA can be found here:

https://developers.google.com/interactive-media-ads/docs/sdks/ios/

https://developers.google.com/interactive-media-ads/docs/sdks/tvos/