# Castlabs Player Android v4.2.49 with Nowtilus SSAI

## STEP 0

Please find the Sample reference application in the Release Notes document. The demo application is available under mediamelon\_demo.zip

<https://mediamelon-builds.s3.amazonaws.com/MM-RELEASE-BUILDS/1922042005/CastlabsPlayer_Android/2022-11-23/demos.zip>[<br>](<https://mediamelon-builds.s3.amazonaws.com/MM-RELEASE-BUILDS/1922042005/CastlabsPlayer_Android/2022-09-28/demos.zip&#xA;>)

## STEP 1

Add the following lines to access the SDK&#x20;

In the Sample Application the following  imports are added in SimplePlaybackDemo.java<br>

```
//MM 1
import com.mediamelon.smartstreaming.mmAd;
import com.mediamelon.smartstreaming.mmAdTimelineInfo;
import com.mediamelon.smartstreaming.MMSSAIEventsListeners;
import com.mediamelon.smartstreaming.MMSmartStreaming;
import com.mediamelon.smartstreaming.MMSmartStreamingPrestoPlayAdaptor;
// MM1
```

## STEP 2

startMediaMelonSDK() API calls all MediaMelon SDK integration API's. To Integrate MediaMelon SDK please call startMediaMelonSDK(). And register Mediamelon SDK using your assigned customerID in StartMediaMelon API. Please refer code block below.

```java
        //MM 2
        boolean sdkIntegration = false; // whether to check SDK integration   
        public void startMediaMelonSDK(){
	        //MediaMelon Castlabs Player Integration
		//MM2A
			sdkIntegration = true;
		        final PlayerController pc = playerView.getPlayerController();
			mmSmartStreamingPrestoPlayAdaptor = new MMSmartStreamingPrestoPlayAdaptor ( getApplicationContext(), pc);
		
		
			mmSmartStreamingPrestoPlayAdaptor.enableLogTrace(true); // Set false in production
			if (!MMSmartStreaming.getRegistrationStatus()) {
				mmSmartStreamingPrestoPlayAdaptor.registerMMSmartStreaming("$PLAYERNAME", "$CUSTOMERID", "$SUBSCRIBERID", "$DOMAINNAME", "$SUBSCRIBERTYPE", "$SUBSCRIBERTAG");
			}
		
			Log.d("MM Reg", "MM Reg:" + MMSmartStreaming.getRegistrationStatus());
			mmSmartStreamingPrestoPlayAdaptor.reportPlayerInfo("CASTLABS", "A1", "1.0");
		//MM2A
	}
	//MM2
```

### Parameters passed in Registration call

| Variable        | Description                                                                                                                                                                          |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| $PLAYERNAME     | Player Name as in Castlabs Player                                                                                                                                                    |
| $CUSTOMERID     | String containing your MediaMelon-assigned Customer ID.                                                                                                                              |
| $SUBSCRIBERID   | String containing your subscriber’s ID. If you do not use subscriber IDs, leave it as it is.                                                                                         |
| $DOMAINNAME     | String containing your section of your subscriber or assets. (Optional)                                                                                                              |
| $SUBSCRIBERTYPE | String containing the subscriber type (e.g. “Free”, “Paid”). If you do not use subscriber types, leave it as it is.                                                                  |
| $SUBSCRIBERTAG  | String containing an additional subscriber-specific information. This is sent in clear (not hashed) to SmartSight and it is advised to not send sensitive information in this field. |

## STEP 3

3.1 Initialize the SDK.&#x20;

3.2 Intialize SSAI tracking

3.3 Start the SDK

Add the below lines following the registration to enable the Nowtilus SSAI Ad Manager in startMediaMelonSDK() API. Please refer the code below.

\
\&#xNAN;***NOTE*** - `boolean enablePollingforSSAI`  variable indicates whether the Mediamelon SDK needs to poll for the VAST URL or not. Please set it to true in case of Castlabs Player.<br>

```java
       public void startMediaMelonSDK(){
       
          //MM2A
             ....
          //MM2A
          
          //MM2B
          // 3.1 Initialize SDK
          // Asset data. This needs to be provided. In case you do not want to use this
          // sample block can be used as is 
              JSONObject obj = new JSONObject();
   				try {
   					obj.put("assetName","SampleLiveStream") ;
   					obj.put("assetId","0001") ;
   					obj.put("videoId","0001") ;
   				} catch (JSONException e) {
   					e.printStackTrace(); }			
              mmSmartStreamingPrestoPlayAdaptor.initialize(mediaURL,obj);
          
             // 3.2 Add SSAI 
             // mMyUri - Media URL
             // vastURL - URL for VAST
             // isLive - True for Live streams and false for VOD
             // The last parameter setupNowtilusAdManager enablePollingforSSAI is alsways set to true
          
             mmSmartStreamingPrestoPlayAdaptor.setupNowtilusAdManager(mediaURL, vastURL, true, true);
             ....
             // 3.3 Start the SDK
             mmVoPlayerAdapter.reportUserInitiatedPlayback();
             //MM2B
         }
         //MM2

```

## STEP 4

Subscribe to AD EVENTS in startMediaMelon() API. Please refer code block below

```java
     //MM 2
     public void startMediaMelonSDK(){
         
         //MM2A
          ......
         //MM2A
         
         //MM2B
          .......
         //MM2B
         
         
         //MM2C
         //subscribe to AD EVENTS
         MMSSAIEventsListeners mmssaiEventsListeners = new MMSSAIEventsListeners() {
			@Override
			public void onAdImpression(mmAd ssaiAdInfo) {
				Log.d("APP SSAI", "onAdImpression:" + ssaiAdInfo.adId);    }

			@Override
			public void onAdComplete(mmAd ssaiAdInfo) {
				Log.d("APP SSAI", "onAdComplete:" + ssaiAdInfo.adId);
			}

			@Override
			public void onCueTimelineAdded(mmAdTimelineInfo timelineInfo) {
				Log.d("APP SSAI", "onCueTimelineAdded totalAds: " + timelineInfo.totalAds);
			}

			@Override
			public void onCueTimelineEnter(mmAd ssaiAdInfo) {
				Log.d("APP SSAI", "onCueTimelineEnter:" + ssaiAdInfo.adId);
			}

			@Override
			public void onCueTimelineExit(mmAd ssaiAdInfo) {
				Log.d("APP SSAI", "onCueTimelineExit:" + ssaiAdInfo.adId);
			}
		};
          mmSmartStreamingPrestoPlayAdaptor.getSSAIAdManager().addListener(mmssaiEventsListeners);
         //MM2C
    }
    //MM2
```

## STEP 5

ADD API for stopping MediaMelon SDK.To stop MediaMelon SDK please call stopMediaMelonSDK(). Please refer code block below&#x20;

```java
    //MM3
        public void stopMediaMelonSDK(){
           if(sdkIntegration) mmSmartStreamingPrestoPlayAdaptor.closeMediaMelonSDK(); 
        }
    //MM3
    
```

## List of AD EVENTS

```
onAdImpression
onAdStarted
onAdFirstQuartile
onAdMidpoint
onAdThirdQuartile
onAdProgress
onAdComplete
onCueTimelineAdded 
onCueTimelineEnter
onCueTimelineExit
```

| Event Callback     | Description                                                               |
| ------------------ | ------------------------------------------------------------------------- |
| onAdImpression     | Fired when an Ad Impression occurs                                        |
| onAdStarted        | Fired when Ad starts playing                                              |
| onAdFirstQuartile  | Fired when Ad playback reaches the First Quartile point                   |
| onAdMidpoint       | Fired when Ad playback reaches the Midpoint                               |
| onAdThirdQuartile  | Fired when Ad playback reaches the Third Quartile point                   |
| onAdProgress       | Fired every second during Ad Playback, used to track Ad Playback progress |
| onAdComplete       | Fired when Ad Playback completes                                          |
| onCueTimelineAdded | Fired when an Ad break information gets added                             |
| onCueTimelineEnter | Fired when an Ad break ( which can contain multiple Ads) starts           |
| onCueTimeLineExit  | Fired when an Ad break ( which can contain multiple Ads) ends             |

## Get Ad Related Information

You can use the below commands from inside any of the AD Events(listed above) that you subscribe to.

1. &#x20;**`ssaiAdInfo.getTotalAds()`**- returns a `int` which signifies the number of Ads in the current Ad break.
2. &#x20;**`ssaiAdInfo.getClickTrackingURLs()`**-returns the click tracking URLs as a *List\<String>.*
3. **`ssaiAdInfo.getClickThroughURLs()`** -returns the clickthrough URLs as a *List\<String>.*
4. **`ssaiAdInfo.getAdSkipOffset()`-** returns the   AD offset in  `seconds.`
5. **`ssaiAdInfo.getCompleteTrackers()`**` ``-` returns the  AD Complete Tracking URLs as a *List\<String>.*
6. **`ssaiAdInfo.getMidpointTrackers()`**` ``-` returns the  AD Midpoint Tracking URLs as a *List\<String>.*
7. **`ssaiAdInfo.getThirdQuartileTrackers()`**` ``-` returns the  AD ThirdQuartile Tracking URLs as a *List\<String>.*
8. **`ssaiAdInfo.getFirstQuartileTrackers()`**` ``-` returns the  AD FirstQuartile Tracking URLs as a *List\<String>.*
9. **`ssaiAdInfo.getImpressionTrackers()`**` ``-` returns the  AD Impression URLs as a *List\<String>.*
10. **`ssaiAdInfo.getAdIndex()`**` ``-` returns the index of the current AD in the AD break.


---

# 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-nowtilus-ssai/mediamelon-player-sdk-android/castlabs-player-android-v4.2.49-with-nowtilus-ssai.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.
