> 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-tvos/bitmovin-tvos-v3.4x-nowtilus-ssai-with-content-provider-metrics.md).

# Bitmovin TVOS v3.4x (Nowtilus SSAI) with Content Provider Metrics

### **Integrating the MediaMelonSmartStreaming Framework**

There are five 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
5. Add the SSAI Manager Delegate
6. Create a new session and update the asset information
7. Enabling Content Provider Metrics

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

#### 1. Import Frameworks

```objectivec
import BitmovinPlayer
import MMSmartStreamingSDK // For Cocoaapods release
or
import MMGenericFramework // For Framework release
```

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

{% hint style="info" %}
After the instance of the player is created, and SourceConfig 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(`mediaURL: String, vastURL: String`)`
{% endhint %}

```swift
private func configureMMSDK(mediaURL: String, vastURL: String) {
        let assetInfo = MMAssetInformation(assetURL: mediaURL, assetID: "ASSET_ID", assetName: "ASSET_NAME", videoId: "VIDEO_ID")
        
        assetInfo.setContentType("CONTENT_TYPE") //Type of content (Movie / Special / Clip / Scene)
        assetInfo.setDrmProtection("DRM_PROTECTION") //Widevine, Fairplay, Playready etc. Unknown means content is protected, but protection type is unknown. For clear contents, do not set this field
        assetInfo.setEpisodeNumber("EPISODE_NUMBER") //Sequence Number of the Episode (string).
        assetInfo.setSeriesTitle("SERIES_TITLE") //Title of the series
        assetInfo.setSeason("SEASON") //Season For example - Season1,2,3 etc
        assetInfo.setGenre("GENRE") //Genre of the content

        // Optional custom metadata
        assetInfo.addCustomKVP("CustomKVP1Key", "CustomKVP1Value")
        assetInfo.addCustomKVP("CustomKVP2Key", "CustomKVP2Value")
        assetInfo.setQBRMode(.QBRModeDisabled, withMetaURL: nil)
        
        let registrationInfo = MMRegistrationInformation(customerID: "CUSTOMER_ID", playerName: "PLAYER_NAME")
        registrationInfo.setSubscriberInformation(subscriberID: "SUBSCRIBER_ID", subscriberType: "SUBSCRIBER_TYPE", subscriberTag: "SUBSCRIBER_TAG", hashSubscriberID: false)
        BitmovinPlayerIntegrationWrapper.setPlayerRegistrationInformation(registrationInformation: registrationInfo, player: player)
        
        let isLive = false;    //Set this 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. isLive field is optional here
        BitmovinPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player, isLive: 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
BitmovinPlayerIntegrationWrapper.cleanUp()
```

#### 4. 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) {
    .
    .
    .
    BitmovinPlayerIntegrationWrapper.cleanUp()
    BitmovinPlayerIntegrationWrapper.disableManifestsFetch(disable: true)
    BitmovinPlayerIntegrationWrapper.initializeAssetForPlayer(assetInfo: assetInfo, registrationInformation: registrationInfo, player: player, isLive: isLive)
}
```

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

#### 5.  Add the SSAIManagerDelegate

Add the SSAIManagerDelegate to the ViewController class in ViewController.swift

```swift
class ViewController: UIViewController, SSAIManagerDelegate 
```

You can now use the 2 delegate functions to get the event information whenever an AD event occurs

```swift
func notifyMMSSAIAdEvents(eventName: MMSSAIAdSate, adInfo: MMSSAIAdDetails)
{
    
}

func notifyMMSSAIAdEventsWithTimeline(eventName: MMSSAIAdSate, adTimeline: [MMSSAIAdDetails]) 
{
    
}    
```

#### 6. Create a new session and update the asset  information

During playback updateAssetInfo can be used to create a new session and update the asset information.  The usage can be seen in the updateAsset function in the ViewController&#x20;

```swift
func updateAsset() {
        let assetInfo = MMAssetInformation(assetURL: mediaURL, assetID: "RandomID", assetName: "Test Asset", videoId: "123456789")
        
        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("testEpisode") //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
        assetInfo.addCustomKVP("CustomKVP1Key", "CustomKVPalue")
        assetInfo.addCustomKVP("CustomKVP2Key", "CustomKVPValue")
        assetInfo.setQBRMode(.QBRModeDisabled, withMetaURL: nil)
          
         // Create a new session and update the Asset info
          BitmovinPlayerIntegrationWrapper.updateAssetInfo(assetInfo: assetInfo, player: player)      
  }
```

#### 7. Enabling Content Provider Metrics <a href="#dz-step-6-update-asset-info" id="dz-step-6-update-asset-info"></a>

Content Provider Metric Reporting is enabled by calling the setContentProviderDetails function defined in the BitmovinPlayerIntegrationWrapper.swift. This needs to be done immediately after the call to configure the Media Melon SDK

```swift
self.configureMMSDK(mediaURL: redirectedMediaURL!, vastURL: vastUrl)
if ( contentProviderDetails == true)
{
    BitmovinPlayerIntegrationWrapper.setContentProviderDetails(url:redirectedMediaURL!)
}

```

The setContentProviderDetails expects the URL with the Content Provider information as shown in the table below.  In case the information is correctly provided it enables content provider metrics  reporting.&#x20;

{% hint style="info" %}
The above code is tested with URLs with the structure:

* <https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8?tbtoken=JWTtoken&provider=tbox&cid=ContentId>&#x20;
  {% endhint %}

| Parameter | Value                                |
| --------- | ------------------------------------ |
| provider  | <p>stzp : Starz<br>tbox: Toolbox</p> |
| tbtoken   | JWT Token for Toolbox endpoint       |
| cid       | Content ID                           |
| sid       | Starz session ID                     |

For enabling Toolbox metrics please pass - provider, tbtoken and cid values as shown below&#x20;

{% hint style="info" %}
<https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8?tbtoken=JWTtoken&provider=tbox&cid=ContentId>
{% endhint %}

For enabling Starz content provider metrics please pass: provider, cid and sid values as shown below

{% hint style="info" %}
<https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8?provider=stzp&cid=ContentId&sid=SessionId>
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mediamelon.com/mediamelon-nowtilus-ssai/mediamelon-player-sdk-tvos/bitmovin-tvos-v3.4x-nowtilus-ssai-with-content-provider-metrics.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
