MediaMelon
  • MediaMelon SDK Integration
  • MediaMelon SDK Events
  • MediaMelon Player SDK Integration
    • React Native
      • React Native Video v5.2.0 with Mediamelon SDK
      • React Native Video v6.4.2 with Mediamelon SDK
    • Web SDK
      • VideoJS Web with Mediamelon Analytics
      • VideoJS Web with Google DAI
      • Shaka Player Web v4
      • MediaMelon Web Kaltura Player Plugin Integration Document
      • NexPlayer Web v4
      • THEOPlayer Web
      • JWPlayer Web
      • Radiant Player Web
      • ChromeCast Player
      • HLSJS Player Web
      • HbbTV SDK
      • Comcast PDK 6
      • Bitmovin Web Player
      • HTML5 Player Web
      • Flow Player Web
      • DashJS Player Web
      • Castlabs Player Web
      • Cordova Plugin Toast (Smart TV)
      • Custom Player Web SDK
      • Plyr Player Web with MediaMelon Analytics
      • React Player SDK with IMA
    • Android SDK
      • App Analytics SDK
      • Bitmovin Android v3.73 with Content Provider Metrics
      • Exoplayer v2.13.2 integration with MediaMelon SDK
      • Exoplayer v2.17.1 with Mediamelon SDK
      • Exoplayer v2.12.2 integration with MediaMelon SDK
      • EXOPlayer-Android(V2.14.2) MediaMelon SDK with Google IMA DAI
      • EXOPlayer-Android(V2.17.1) MediaMelon SDK with Google IMA DAI
      • Exoplayer v2.11
      • Exoplayer v2.18.1 with Mediamelon SDK
      • Theoplayer v6.0.0 with Mediamelon SDK
      • Theoplayer v4.12.6 with Mediamelon SDK
      • Theoplayer v7.5.0 with Mediamelon SDK
      • Exoplayer v2.13.3 integration with MediaMelon SDK
      • Kaltura Android Player Integration with Mediamelon SDK
      • Media3 v1.3.0 and ExoPlayer 2.19.1 with MediaMelon SDK
      • Media3 v1.3.1 with MediaMelon SDK
      • MediaMelon Android Media3 v1.1.1 SDK Integration Document
      • Media3Player-Android(V1.3.0) MediaMelon SDK with Google IMA
    • Roku SDK
      • Roku SDK
      • Roku with RAF SDK
      • Roku with IMA SDK
    • iOS SDK
      • AVPlayer (Cocoapods)
      • AVPlayer with Google DAI SDK ( Framework )
      • AVPlayer Quality Of Experience SDK
      • AVPlayer Generic Framework
      • AVPlayer with Google DAI (Cocoapods)
      • Bitmovin iOS v3.44 with Content Provider Metrics
      • THEOPlayer XCFramework
      • THEOplayer (Cocoapods)
      • MediaMelon iOS Kaltura Player Plugin Integration Document
    • tvOS SDK
      • AVPlayer tvOS XCFramework
      • THEOPlayer tvOS XCFramework
    • Toast SDK
    • Custom Player C++ SDK
    • C++ SDK QoE Ads
    • Ad Integrations
      • Google IMA
      • FreeWheel
      • ServerSide.AI
  • SmartSight Analytics
    • Product Features
    • QBR Streaming
  • SmartSight API's
    • API Overview
      • Metric and Dimensions Dictionary
      • General Guidelines
      • Video Experience
      • Ad Experience
      • Smartquery Insights
      • Errors
      • Alerts
    • Use-case dictionary
Powered by GitBook
On this page
  • Step 0: Creating AVPlayer based media player application
  • Step 1: Building the MediaMelonSmartStreaming Framework
  • Step 2: Integrating the MediaMelonSmartStreaming Framework

Was this helpful?

  1. MediaMelon Player SDK Integration
  2. iOS SDK

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

cd ~/
mkdir sampleintegration
cd sampleintegration/

Pull the Sample Application from https://sdk.mediamelon.com/$CustomerID/AVPlayerWithGoogleIMA.zip and unzip it

wget https://sdk.mediamelon.com/<Customer ID>/AVPlayerWithGoogleIMA.zip

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

sudo gem install cocoapods
pod init
touch Podfile
open Podfile

Edit the Podfile

target 'AVPlayerWithGoogleIMA' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'MediaMelonSmartStreaming/AVPlayerWithGoogleDAI', '~> 1.1.13'
  # Pods for SwiftDemo
end

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:

  1. Importing the framework

  2. Providing asset information for the content before starting the player and after creating its instance

  3. Cleaning up the SDK integration session

  4. 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.swiftas mentioned below

1. Import Frameworks

import AVFoundation
import GoogleInteractiveMediaAds
import MediaMelonSmartStreaming

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

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")
    AVPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player)
    // 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 configureMMSDKwithURLcall. 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

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

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)
}

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

    //Integration Step 6
    func streamManager(_ streamManager: IMAStreamManager!, didReceive error: IMAAdError!) {
        mmAdManagerDelegate?.streamManager?(streamManager, didReceive: error)
    }
   
    func streamManager(_ streamManager: IMAStreamManager!, didReceive event: IMAAdEvent!) {
        mmAdManagerDelegate?.streamManager?(streamManager: streamManager, didReceive: event)
    }

PreviousAVPlayer Generic FrameworkNextBitmovin iOS v3.44 with Content Provider Metrics

Last updated 1 year ago

Was this helpful?