AVPlayer with Google DAI SDK ( Framework )
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
cd ~/
mkdir sampleintegration
cd sampleintegration/
Pull the Sample Application from the link available in the Release Notes
Get the sample app dependencies by changing the directory to the ~/sampleintegration/AVPlayerWithGoogleIMA
and execute the following commands
Step 1: Setting up the Sample Application Environment
Execute the following two commands on the terminal in the folder ~/sampleintegration/AVPlayerWithGoogleIMA
sudo gem install cocoapods
pod init
touch Podfile
Step 2: Integrating the MMAVPlayerWithGoogleDAI Framework
There are four steps involved for integrating the MediaMelon Player SDK using the MMAVPlayerWithGoogleDAI 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
Open the project file ~/sampleintegration/AVPlayerWithGoogleIMA/AVPlayerWithGoogleIMA.workspace
in XCode and edit the file ViewController.swift
as mentioned below
1. Import Frameworks
import AVFoundation
import GoogleInteractiveMediaAds
import MMAVPlayerWithGoogleDAI
2. Provide Asset information
private func configureMMSDKWithURL(urlStr: String, player: AVPlayer) {
//Integration Step 1
print("Integrating with \(String(describing: AVPlayerIntegrationWrapper.getVersion()))")
AVPlayerIntegrationWrapper.shared.enableLogTrace(logStTrace: true)
let assetInfo = MMAssetInformation(assetURL: hlsURLStr, assetID: String(arc4random()), assetName: "assetNameRandom", videoId: "VIDEO_ID")
// Optional Asset metadata
assetInfo.setContentType("Movie") //Type of content (Movie / Special / Clip / Scene)
assetInfo.setDrmProtection("Fairplay") //Widevine, Fairplay, Playready etc. Unknown means content is protected, but protection type is unknown. For clear contents, do not set this field
assetInfo.setEpisodeNumber("10") //Sequence Number of the Episode (string).
assetInfo.setSeriesTitle("testSeries") //Title of the series
assetInfo.setSeason("testSeason") //Season For example - Season1,2,3 etc
assetInfo.setGenre("testGenre") //Genre of the content
// Optional custom metadata
assetInfo.addCustomKVP("CustomKVP1Key", "CustomKVP1Value")
assetInfo.addCustomKVP("CustomKVP2Key", "CustomKVP2Value")
assetInfo.setQBRMode(.QBRModeDisabled, withMetaURL: nil)
let registrationInfo = MMRegistrationInformation(customerID: "<your_customer_id>", playerName: "<player_name>")
registrationInfo.setPlayerInformation(brand: "<player_brand>", model: "<player_model>", version: "<player_version>")
registrationInfo.setSubscriberInformation(subscriberID: "<subscriber_id>", subscriberType: "<subscriber_type>", subscriberTag: "SubscriberTAG", hashSubscriberID: true)
//To hash the subscriber ID, set hashSubscriberID to true. To leave the subscriber ID unhashed, set it to false. (This field is optional)
//Set isLive to true for a live stream or false for a VOD stream. If isLive is not set here, it will be handled internally by the SDK.
AVPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player, isLive: false)
// Create the Ad Manager Delegate that will be used for MediaMelon SDK
self.mmAdManagerDelegate = MMIMAAdManager.sharedManager
//End of integration Step 1
}
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
@var mmSDKInitialised: Bool = false
oobjc func handleAVPlayerAccess(notification: Notification) {
guard let playerItem = notification.object as? AVPlayerItem,
let lastEvent = playerItem.accessLog()?.events.last else {
return
}
guard let indicatedStream = lastEvent.uri else { return }
var urlComps = urlString.components(separatedBy: "/")
urlComps.removeLast()
var streamComps = indicatedStream.components(separatedBy: "/")
streamComps.removeLast()
//Integration Step 2
if urlComps != streamComps && !mmSDKInitialised {
self.mmSDKInitialised = true
self.configureMMSDKWithURL(urlStr: indicatedStream, player: self.player)
}
}
3. Cleaning up the SDK Session
AVPlayerIntegrationWrapper.cleanUp()
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()
private func configureMMSDKWithURL(hlsURLStr: String) {
.
.
.
AVPlayerIntegrationWrapper.cleanUp()
AVPlayerIntegrationWrapper.disableManifestsFetch(disable: true)
AVPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player, isLive: false)
}
7. Specifying App Name and App Version
App Name and App Version can be specified by using the following API
AVPlayerIntegrationWrapper.shared.reportAppData(appName: "AVPlayerDemoApp", appVersion: "1.0.0")
Last updated
Was this helpful?