AVPlayer with Google DAI (Cocoapods)
This guide provides detailed instructions on integrating the MediaMelon Player SDK into an iOS Media Player Application that supports Google Dynamic Ad Insertion
Step 0: Creating AVPlayer based media player application
Create a directory for integration by doing the following. Open the terminal, change directory to the home directory, and create a folder sampleintegration
Pull the Sample Application from https://sdk.mediamelon.com/$CustomerID/AVPlayerWithGoogleIMA.zip
and unzip it
Get the sample app dependencies by changing the directory to the ~/sampleintegration/AVPlayerWithGoogleIMA
and execute the following commands
Step 1: Building the MediaMelonSmartStreaming Framework
Execute the following two commands on the terminal in the folder ~/sampleintegration/AVPlayerWithGoogleIMA
Edit the Podfile
Finally, install the pod pod install
Google IMA SDK will be added automatically as a dependency to MediaMelon SDK. If you have added the Google IMA SDK in your project, please remove it
Step 2: Integrating the MediaMelonSmartStreaming Framework
There are four steps involved for integrating the MediaMelon Player SDK using the MediaMelonSmartStreaming Framework:
Importing the framework
Providing asset information for the content before starting the player and after creating its instance
Cleaning up the SDK integration session
Disable manifest fetching by the SDK
All AVPlayer related code of the sample application can be found in the Swift class ViewController.swift
Open the project file ~/sampleintegration/AVPlayerWithGoogleIMA/AVPlayerWithGoogleIMA.workspace
in XCode and edit the file ViewController.swift
as mentioned below
1. Import Frameworks
2. Provide Asset information
After the instance of the player is created, and AVAsset is set with it, we should set the asset information and send it to before starting its playback. In ViewController.swift, call function self.configureMMSDKwithURL(urlString, self.player
In case of Google DAI we use IMALiveStreamRequest
or IMAVODStreamRequest
to obtain a Live or VOD stream respectively. The internal URL provided to AV Player needs to be used in the configureMMSDKwithURL
call. This can be obtained as follows
3. Cleaning up the SDK Session
We need to clean up the SDK session once the playback completes. The SDK internally manages the cleanup for most of the cases. For example - when playback finishes, or some error is notified.
However, in some error cases, like network reachability issues, the error notification is delayed. And before this error notification is available, the user may trigger another session. Therefore, it is advised to clean up the session once the playback finishes.
We recommend cleanup at the following two places.
When the view controller hosting the post roll ad terminates
When the player is restarted
5. Disable manifest fetching by the SDK
If your workflow restricts the manifest to be accessible from both player and the MediaMelon Player SDK simultaneously, then, you can disable the fetch of manifest via disableManifestsFetch()
in method _configureMMSDKwithURL()
Note: Disable Manifest Fetch is Optional
6. Reporting events and errors
Reporting of the Ad Events and Errors is done by implementation of the following delegates which sends the Ad event and Error information to the MediaMelon.SDK
Last updated