Google IMA / DAI
The AmpIMA plugin offers a quick way to integrate AmpPlayer with the Interactive Media Ads by Google. This plugin will handle the interaction between the AmpPlayer with the plugin as well as the ads insertion or DAI stream playback.
If you desire to check out a basic implementation please refer to our application samples:
Adding the Plugin to the Xcode project
Manual Installation
To manually install the plugin you’ll need to download our latest distribution. You will be using AmpIMA.xcframework
and the AmpCore.xcframework
to integrate this plugin.
The latest version of the Google IMA SDK used by this plugin is 3.23.0 on iOS and 14.3.0 on tvOS , newer versions may be used, but you may run into unexpected errors until an update is released. |
After acquiring the frameworks you can just drag them to you Xcode project directory.
The last step, is to mark every imported framework for Embed & Sign
in the project’s general tab.
CocoaPods
If you don’t have CocoaPods installed, refer to the CocoaPods documentation. To use CocoaPods, first create a Podfile in the directory containing the Xcode project. For the AmpIMA plugin, the Podfile should look like this:
target "ProjectName" do
use_frameworks!
pod 'AmpCore'
pod 'AmpIMA'
pod 'GoogleAds-IMA-iOS-SDK'
end
Once you have added the Podfile just run the command pod install --repo-update
in the directory it’s located. Once the command has been completed you should se a new .xcworkspace
file in your folder. Now you can start integrating the library.
Implementation
You need a working implementation of the AmpPlayer before using this plugin. If you need the implementation guide for AmpPlayer please refer to our documentation.
Import
The first step is to import the AmpIMA plugin. In the most likely scenario you will need the AmpCore library, and you may need the Google IMA SDK in specific cases.
import AmpCore
import AmpIMA
import GoogleInteractiveMediaAds
Creating a new instance
To use this plugin you should first initialize it. You need to specify the player being used as well as the view were the ads will be displayed.
let manager = AmpIMAManager(ampPlayer: player, videoView: player.playerView!)
Do not create multiple instances of the AMPIMAManager. This could create unwanted behaviors since it wouldn’t be following Google’s recomendation against intancing more than one IMAAdsLoader. |
Requesting DAI streams
To request a DAI live or VoD stream you won’t need to call the AmpPlayer.play(url:String)
method. Instead use thismethod for requesting the DAI streams:
manager.requestLiveStream(assetkey: "sN_IYUG8STe1ZzhIIE_ksA")
manager.requestVodStream(contentSourceID: "2528370", videoID: "tears-of-steel")
You can also add a fallback URL on this methods so that if the stream couldn’t be loaded the fallback will still be played. |
Requesting IMA ads
To request IMA ads just send your Ad Tag provided by Google to this method.
manager.requestImaAds(adTagUrl: adsUrl)
This will request the ads and display them at the proper time.
Listening to events
This plugin will automatically hook the events from the IMA SDK, both client-side ads and DAI streams, and send the proper AMPPlayer Events. However, in case you want to handle yourself some of the events on IMA, we provide the means to do this by passing a valid delegate to the manager.
manager.imaDelegate = self
manager.daiDelegate = self
Additional Information
This guide was written on 4/27/2020 and it’s last revision was made on 7/22/2024. If you need any additional support please contact us through our offical support email.