# Theoplayer SDK Integration Document

**Step 1:** [Prerequisites](#step-1-prerequisites)

**Step 2:** [Set up the build environment](#step-2-set-up-the-build-environment)

**Step 3:**[ Register SDK](#step-3-register-sdk)

**Step 5:** [Initialize Session](#step-3-initialize-session-and-report-user-intent-to-playback)

**Step 10:** [Report Ended State](#step-5-report-ended-state-when-the-player-instance-is-released)

### Step 1: Prerequisites

* MediaMelon SmartSight SDK `smartstreaming_release.aar`

### Step 2: Set up the build environment&#x20;

The SDK files are added to the build environment and the required network permissions are enabled.&#x20;

1. Copy smartstreaming-release.aar provided with the release package to the theoplayer project, Example `app/libs/smartstreaming-release.aar`&#x20;
2. Add the following library to `app/build.gradle` :-

```gradle
dependencies {
  .
  .
  .
   //<!-- <MMSmartStreaming 1a> -->
    api files ('smartstreaming-release.aar')
  //<!-- </MMSmartStreaming 1a> -->
}
```

Add network permissions to&#x20;

`app/src/main/AndroidManifest.xml`

```java
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
```

### Step 3: Register SDK

The player application must register the SDK and provide player information once when the application launches. Please note that values provided in this integration step persist across video sessions. This is typically done when the player itself is initialized.&#x20;

\
Step 3a: Import packages

`app/src/main/java/com/theoplayer/theoplayerexample/MainActivity.java`

```java
// <MMSmartStreaming 2a>
import com.mediamelon.smartstreaming.MMQBRMode;
import com.mediamelon.smartstreaming.MMSmartStreaming;
import com.mediamelon.smartstreaming.MMSmartStreamingTheo;
import com.mediamelon.smartstreaming.MMSmartStreamingInitializationStatus;
import com.mediamelon.smartstreaming.MMSmartStreamingObserver;
import java.util.ArrayList;
import android.util.Log;
// </MMSmartStreaming 2a>
```

#### Step 3b: Registration

&#x20;Perform registration tasks by modifying the `onCreate()` method in `app/src/main/java/com/theoplayer/theoplayerexample/MainActivity.java`

{% hint style="info" %}
The `enableLogTrace()` feature should be enabled for testing during the integration process. Set this to False before releasing the player to production
{% endhint %}

```java
public void onCreate(Bundle savedInstanceState) {
  ...
   @Override
            public void onClick(View v) {
                if (theoPlayerView.getPlayer().isPaused()) {
                    theoPlayerView.getPlayer().play();
                } else {
                    theoPlayerView.getPlayer().pause();
                }
            }
        });
        //<MMSmartStreaming 2b>
        MMSmartStreamingTheo.enableLogTrace(<boolean>); //set to "false" before releasing player to production
        if (MMSmartStreamingTheo.getRegistrationStatus() == false){ //Check if it is the first time Registration process is done
            MMSmartStreamingExo2.setDeviceInfo($DEVICE_MARKETING_NAME);
            MMSmartStreamingExo2.registerMMSmartStreaming($PLAYERNAME, $CUSTOMERID, $SUBSCRIBERID, $DOMAINNAME, $SUBSCRIBERTYPE, $SUBSCRIBERTAG,$hashSubscriberId);
            MMSmartStreamingExo2.reportPlayerInfo("CustomPlayerName","Player_Version", "1.0");
            MMSmartStreamingExo2.getInstance().setContext(getApplicationContext()); //Please make sure to provide the application's context here, and not the activity's context
            MMSmartStreamingExo2.getInstance().reportAppInfo($APP_NAME,$APP_VERSION);
            MMSmartStreamingExo2.getInstance().reportVideoQuality($VIDEO_QUALITY);
            }
        // </MMSmartStreaming 2b>
  }
```

* **`hashSubscriberID`**: To hash the subscriber ID, set it to <mark style="color:orange;">`true`</mark>. To leave the subscriber ID un-hashed, set it to <mark style="color:orange;">`false`</mark>.This is optional

### Step 4: Initialize Session  <a href="#step-3-initialize-session-and-report-user-intent-to-playback" id="step-3-initialize-session-and-report-user-intent-to-playback"></a>

The SDK must be initialized at the start of each video session. Initialization includes setting the application context, initializing the playback session, and indicating the intent for playback with the SDK.

`app/src/main/java/com/theoplayer/theoplayerexample/MainActivity.java`

```java
// after player is initialised and not null anymore
    String mediaUrl = "get the mediaURL from your application"
    String assetId  = "assetID"; //enter you assetId here
    String assetName = "assetNAME"; // enter your assetname here
    String videoId = "videoID"; // enter your videoId here
    ContentMetadata cm  = new ContentMetadata();
    String episodeNumber = "EpisodeNumber";
    String season = "Season";
    String genre = "Genre";
    String drmProtection = "drmProtection";
    String contentType = "contentType";
    String title = "Title";
    cm.videoId=videoId;
    cm.seriesTitle=title;
    cm.season=season;
    cm.genre=genre;
    cm.episodeNumber=episodeNumber;
    cm.drmProtection=drmProtection;
    cm.contentType=contentType;
    cm.assetName=assetName;
    cm.assetId=assetId;
    JSONObject contentMetadata = cm.getJSONObject();
    //optional content metadata
    MMSmartStreamingTheo.getInstance().initializeSession(player, MMQBRMode.QBRModeDisabled, mediaUrl, null,contentMetadata,isLive);
```

{% hint style="info" %}

* **`isLive`**: Set it to <mark style="color:orange;">`true`</mark> for a live video and <mark style="color:orange;">`false`</mark> for a VOD video. This is optional.
  {% endhint %}

### &#x20;Step 5: Report Ended State <a href="#step-5-report-ended-state-when-the-player-instance-is-released" id="step-5-report-ended-state-when-the-player-instance-is-released"></a>

```java
@Override
protected void onDestroy() {
    super.onDestroy();
    //MM
    MMSmartStreaming.getInstance().reportPlayerState(MMPlayerState.STOPPED);
    //MM
    theoPlayerView.onDestroy();
}
```
