> For the complete documentation index, see [llms.txt](https://docs.mediamelon.com/mediamelon-nowtilus-ssai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediamelon.com/mediamelon-nowtilus-ssai/mediamelon-player-sdk-ios/av-player-with-nowtilus-ssai-old.md).

# AV Player with Nowtilus SSAI (old)

### **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`

```javascript
cd ~/
mkdir sampleintegration
cd sampleintegration/
```

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

```
wget https://sdk.mediamelon.com/$CustomerID/iOS/AVPlayer_SampleApplication.zips
```

### **Step 1: Get the MMGenericFramework Static Framework Library**

Download the MMGenericFramework **static** faremwork &#x20;

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**&#x20;

There are five steps involved for integrating the MediaMelon Player SDK using the MediaMelonSmartStreaming Framework:

1. Add the appropriate MMGenericFramework to the AV Player Sample Application
2. Providing asset information for the content before starting the player and after creating its instance
3. Disable manifest fetching by the SDK
4. Initializing SSAI
5. Cleaning up the SDK integration session

{% hint style="info" %}
All AV Player related code of the sample application can be found in the Swift class`ViewController.swift`&#x20;
{% endhint %}

#### 1. Import Frameworks

```objectivec
import MMGenericFramework
```

#### &#x20;2. Provide Asset information

{% hint style="info" %}
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)`
{% endhint %}

```swift
private func configureMMSDKWithURL(urlStr: String, vastURLStr: String, player: AVPlayer) {
        print("Integrating with \(String(describing: AVPlayerIntegrationWrapper.getVersion()))")
        let assetInfo = MMAssetInformation(assetURL: urlStr, assetID: String(arc4random()), assetName: "assetNameRandom", videoId: "VIDEO_ID")
        assetInfo.addCustomKVP("CustomKVP1Key", "CustomKVP1Value")
            assetInfo.addCustomKVP("CustomKVP2Key", "CustomKVP2Value")
            assetInfo.setQBRMode(.QBRModeDisabled, withMetaURL: nil)
        let registrationInfo = MMRegistrationInformation(customerID: "202290422", playerName: "AVPLayer")
        registrationInfo.setPlayerInformation(brand: "Apple", model: "iPhone 11", version: "14.1")
        registrationInfo.setSubscriberInformation(subscriberID: "<subscriber_id>", subscriberType: "<subscriber_type>", subscriberTag: "TAGIT")
        AVPlayerIntegrationWrapper.shared.mmssaiManagerDelegate = self
        AVPlayerIntegrationWrapper.disableManifestsFetch(disable: true)
        AVPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player)
        //Initialize SSAI
        AVPlayerIntegrationWrapper.shared.initialiseSSAIAdManager(mediaUrl: self.mediaURL, vastUrl: self.vastURL, isLive: self.isLive)
 }
```

#### 3. Cleaning up the SDK Session

{% hint style="info" %}
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.&#x20;

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.&#x20;

We recommend cleanup at the following two places.

* When the view controller hosting the post roll ad terminates
* When the player is restarted
  {% endhint %}

```objectivec
AVPlayerIntegrationWrapper.shared.stopSSAIAdManager()
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()`

```swift
private func configureMMSDKWithURL(mediaURL: String, vastURL: String) {
    .
    .
    .
    AVPlayerIntegrationWrapper.cleanUp()
    AVPlayerIntegrationIntegrationWrapper.disableManifestsFetch(disable: true)
    AVPlayerIntegrationIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player)
}
```

{% hint style="info" %}
Note: Disable Manifest Fetch is Optional
{% endhint %}

#### 5.  Add the MMSSAIManagerDelegate

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. &#x20;

```swift
class ViewController: UIViewController, MMSSAIManagerDelegate 
.....
    func notifyMMSSAIAdEventsWith(eventName: MMSSAIAdSate, adInfo: MMSSAIAdDetails) {
        
            print("---------------------------------------------------")
            print(" Ad Id :",adInfo.adId )
            print(" Ad Title :",adInfo.adTitle )
            print(" Ad Server :",adInfo.adServer )
            print(" Ad Duration :",adInfo.adDuration )
            print(" Ad Position :",adInfo.position )
            print(" Ad Event :",eventName )
            print("---------------------------------------------------")
    }


```

&#x20;**6. 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.

```swift
private func configureMMSDKWithURL(mediaURL: String, vastURL: String) {
    .
    .
    .
     
        AVPlayerIntegrationWrapper.shared.initialiseSSAIAdManager(mediaUrl: mediaURL, vastUrl: vastURL, isLive: true)
}
```

#### 7. Stop the SSAI Ad Manager &#x20;

To stop the SSAI Ad Manager call the following API

```swift

AVPlayerIntegrationWrapper.shared.stopSSAIAdManager()
```

### **Step 3:  Adding multiple static frameworks including the MMGeneric (Static) Framework**&#x20;

###

```javascript
libtool -static -o MyToplevelSDK.framework MMGeneric.framework/MMGenericFramework AnotherSDK.framework/AnotherSDK
```
