Step 0: Creating AV Player 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
cd ~/
mkdir sampleintegration
cd sampleintegration/
Step 1: Get the MMGenericFramework Static Framework Library
Download the MMGenericFramework static faremwork
Copy the MMGenericFramework static framework to the AVPlayerWithNowtilusSSAi directory
If you are building for the simulator use the MMGenericFramework.framework in the iphonesimulator-x86 and which building for the device use the MMGenericFramework.framework in the iphoneos-arm64 directory
Step 2: Integrating the MMGeneric Framework with the AV Player Sample Application
There are a few steps involved for integrating the MediaMelon Player SDK using the MediaMelonSmartStreaming Framework:
Add the appropriate MMGenericFramework to the AV Player Sample Application
Add the AVPlayerIntegrationWrapper.swift file from the Wrapper directory
Provide asset information for the content before starting the player and after creating its instance
Cleaning up the SDK Session
Disable manifest fetching by the SDK
Add the MMSSAIAdManagerDelegate callbacks
Initializing SSAIAd Manager
Stop the Ad Manager
All AV Player related code of the sample application can be found in the Swift classViewController.swift
1. Import Frameworks
import MMGenericFramework
2. Ad the AVPlayerIntegrationWrapper.swift file
This is the integration layer between the Media Melon Framework and AV Player. This needs to be added to the project. Unless absolutely necessary , this file should not be modified.
3. Provide Asset information
After the instance of the player is create, we should set the asset information and send it to before starting its playback. In ViewController.swift, call function self.configureMMSDKwithURL(mediaURL: String, vastURL: String, player: AVPlayer)
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
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()
Add the MMSSAIManagerDelegate the ViewController class in ViewController.swift. This delegate will be used for receiving Ad related events and data. At every Ad event the Delegate will fire the notifyMMSSAIAdEventsWith function. This can be used to display Ad related data, enable or disable Ad skipping etc.
class ViewController: UIViewController, MMSSAIManagerDelegate
.....
func notifyMMSSAIAdEventsWith(eventName: MMSSAIAdSate, adInfo: MMSSAIAdDetails) {
if (eventName == MMSSAIAdSate.adPlaying)
{
print ("Ad progress ", ((AVPlayerIntegrationWrapper.getAdPlaybackTime(adInfo: adInfo)*100)/AVPlayerIntegrationWrapper.getAdDuration(adInfo: adInfo)))
}
else
{
print("---------------------------------------------------")
print(" Ad Id :",AVPlayerIntegrationWrapper.getAdId(adInfo: adInfo))
print(" Ad Title :",AVPlayerIntegrationWrapper.getAdTitle(adInfo: adInfo) )
print(" Ad Index :",AVPlayerIntegrationWrapper.getAdIndex(adInfo: adInfo)," of ", AVPlayerIntegrationWrapper.getAdTotalAdsInPod(adInfo: adInfo) )
print(" Ad Server :",AVPlayerIntegrationWrapper.getAdServer(adInfo: adInfo))
print(" Ad Duration :",AVPlayerIntegrationWrapper.getAdDuration(adInfo: adInfo) )
print(" Ad Position :",AVPlayerIntegrationWrapper.getAdPosition(adInfo: adInfo) )
print(" Ad Event :",eventName )
if ( eventName == MMSSAIAdSate.adImpression)
{
let clickURL = AVPlayerIntegrationWrapper.getClickThroughURL(adInfo: adInfo)
let clickTrackingURL = AVPlayerIntegrationWrapper.getClickTrackingURL(adInfo: adInfo)
print("Video Click URL:", clickURL)
print("Video Click Tracking URL:", clickTrackingURL)
}
print("---------------------------------------------------")
}
}
Ad Events Supported
adCueTimelineStart
Fired at the start of an Ad break
adImpression
Fired on Ad Impression
adStarted
Fired on start of Ad Play
adPlaying
Fired every 1s during Ad Playback
adFirstQuartile
Fired when Ad playback reached the 25% mark
adMidPoint
Fired when the Ad playback reaches the 50% mark
adThirdQuartile
Fired when Ad Playback reaches the 75% mark
adCompleted
Fired when Ad Playback reaches 100% mark
adCueTimelineEnd
Fired at the end of an Ad break
adSkipped
Fired when an Ad break is skipped
Sample output
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adCueTimelineStart
---------------------------------------------------
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adImpression
Video Click URL: XXXXXXXXXXXXXXX
Video Click Tracking URL: XXXXXXXXXXXXXXXXXXX
---------------------------------------------------
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adStarted
---------------------------------------------------
Ad progress 4
Ad progress 8
Ad progress 12
Ad progress 16
Ad progress 20
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adFirstQuartile
---------------------------------------------------
Ad progress 24
Ad progress 28
Ad progress 32
Ad progress 36
Ad progress 40
Ad progress 44
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adMidpoint
---------------------------------------------------
Ad progress 48
Ad progress 52
Ad progress 56
Ad progress 60
Ad progress 64
Ad progress 68
Ad progress 72
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adThirdQuartile
---------------------------------------------------
Ad progress 76
Ad progress 80
Ad progress 84
Ad progress 88
Ad progress 92
Ad progress 96
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adCompleted
---------------------------------------------------
---------------------------------------------------
Ad Id : 502180
Ad Title : Video_4
Ad Index : 1 of 1
Ad Server : VMAX
Ad Duration : 25
Ad Position : MID
Ad Event : adCueTimelineEnd
---------------------------------------------------
7. Initialize the SSAI Ad Manager
Initialize the SSAI Ad Manager to track the Ads and report Ad related metric. For live stream the last parameter isLive is set to true. There are different ways in which the Ad manager can be initialized
Mode 1: Poll for Vast and Manifest Mode ( Default mode )
AVPlayerIntegrationWrapper.shared.initialiseSSAIAdManager(mediaUrl: self.mediaURL, isLive: self.isLive, pollForVast: false) // Poll for vast set to false used the metadatacollector for accesing manifest data
8. Stop the SSAI Ad Manager
To stop the SSAI Ad Manager call the following API