# THEOplayer (Cocoapods)

### **Step 1: Add** the MediaMelon Player SDK using **the MMSmartStreaming Framework**

Navigate to your project folder using the terminal, if you don't have CocoaPods installed, Please install it using the below commands in terminal

```cpp
sudo gem install cocoapods
pod init
touch Podfile
open Podfile
```

Add the MediaMelonSmartStreaming pod using the below lines

```cpp
target '<SamplePorject_name>' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'MediaMelonSmartStreaming-THEO', '~> 1.0.0'
  # Pods for <SamplePorject_name>
end
```

Finally, install the pod `pod install`

### **Step 2: Integrating the MMSmartStreaming Framework**

There are four steps involved for integrating the SmartSight Player SDK

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

#### **1. Import Frameworks**

```cpp
import THEOplayerSDK
// MediaMelon Integration #1
import MediaMelonSmartStreaming_THEO
```

#### 2. Provide asset information

2a) Add the following method to integrate the MediaMelon Player SDK to the class `ViewController`

```cpp
 class ViewController: UIViewController {
 var theoplayer: THEOplayer!
 // MediaMelon Integration #2a
 func integrateMMSDK(){
     //TheoMMIntegration.shared.enableLogTrace(logStTrace: true)
     let regInfo = MMRegistrationInformation(customerID: $CUSTOMERID, playerName:$PLAYERNAME)
     regInfo.setPlayerInformation(brand: $PLAYERBRAND, model:$PLAYERMODEL, version: $PLAYERVERSION)
     regInfo.setSubscriberInformation(subscriberID: $SUBSID, subscriberType: $SUBSTYPE, subscriberTag: $SUBSTAG)
     TheoMMIntegration.setPlayerRegistrationInformation(registrationInformation: regInfo, player: theoplayer)
 }
```

{% hint style="info" %}
Call to `setPlayerRegistrationInformation` is mandatory.Call to `setPlayerInformation` and `setSubscriberInformation` is optional.
{% endhint %}

2b) Call the method integrateMMSDK after setting up the player

```cpp
override func viewDidLoad() {
      super.viewDidLoad()
      setupTheoPlayer()
      //Integration Step 2b
      integrateMMSDK()
      self.theoplayer.source = sampleSource
}
```

2c) Create and Set the Asset Information

The application may like to set the auxiliary information of the asset so that it can be recorded in the Smartsight. This information could be assetId, assetName, videoId (describing the title to which assets belong), custom metadata etc. The app can produce this information to the SmartSight Player SDK by utilizing the metadata field of the `SourceDescription` used by the Theo player.

```cpp
let assetInfo = MMAssetInformation(assetURL: $ASSETURL, assetID: $ASSETID, assetName: $ASSETNAME, videoId: $VIDEOID)
     assetInfo.addCustomKVP($CUSTOMKEY, $CUSTOMVALUE)
     let encodedAssetInfo = try? JSONEncoder().encode(assetInfo)
     var jsonAssetInfo = ""
     if let encodedAssetInfo = encodedAssetInfo{
         jsonAssetInfo = String(data: encodedAssetInfo, encoding: .utf8) ?? ""
}
```

2d) Adding Custom parameters.&#x20;

Call to `addCustomKVP` is optional. However, when a call is made, setting both custom key and the value is mandatory

```cpp
return SourceDescription(
         source: TypedSource(
             src: "https://cdn.theoplayer.com/video/elephants-dream/playlist.m3u8",
             type: "application/x-mpegurl"
         ),
         //Integration Step 2d
         metadata : MetadataDescription(metadataKeys: [TheoMMIntegration.KAssetInformationKey:jsonAssetInfo])
 )
```

#### 3) Cleanup of session

When the view controller used for playback is removed, call the cleanUp method of the SmartSight Player SDK and add the following method in class `ViewController`

```cpp
 deinit{
     TheoMMIntegration.cleanUp()
 }
```

#### 4) Disable Manifest

{% hint style="info" %}
&#x20;Disable Manifest Fetch is optional
{% endhint %}

&#x20;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 `integrateMMSDK()`

```cpp
 func integrateMMSDK(){
     .
     .
     .
     .
     TheoMMIntegration.setPlayerRegistrationInformation(registrationInformation: regInfo, player: theoplayer)
     TheoMMIntegration.disableManifestsFetch(disable: true)
 }
```


---

# Agent Instructions: 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:

```
GET https://docs.mediamelon.com/mediamelon/smartsight-player-sdk-integration/ios/theoplayer-cocoapods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
