C++ Based Player SDK(Nowtilus SSAI)

Step by step integration of the Mediamelon Player SDK with Nowtilus SSAI for C++ based Player

Step1: Fetching Media Data

If type of the stream is live fetch the media URL and vast URL through an API call. If type of the stream is VoD fetch the media data in the form of JSON which also contains the ad data.

Step2: Initialise SSAI Ad Manager

After the fetching the media data, initialise the SSAI Ad Manager by sending the media data into it. Please refer to the below code for initialisation:

MMNowtilusSSAIAdManager* adManager = new MMNowtilusSSAIAdManager();

if(adManager){
        adManager->mmSSAIClientInit(<mediaUrl>, <vastUrl>, <isLive>, <json_VOD_response>);
        IMMSSAIEventsListeners* ad_observer = new mmSSAIEventListener;
        if(ad_observer){
                adManager->addListener(ad_observer);
        }
}

Step3: Send Playhead Position to the Ad Manager

For SDK to detect the ads and fire callbacks for ad events, absolute playhead position should be shared to the MediaMelon SDK. This position value should be shared through reportPlaybackPosition function call. The position value should be different for live and VoD streams as mentioned below:

Live Stream: Pass the absolute playhead position of the player in the unix timestamp format in milliseconds.

VoD Stream: Pass the absolute playhead position of the player in milliseconds.

adManager->reportPlaybackPosition(<playheadPosition>);

Step4: Listen for the Ad Callbacks

When the SSAI Ad Manger detects an ad, a series of ad callbacks will be fired and those callbacks can be listened as shown in the below code snippet.

class  mmSSAIEventListener : public IMMSSAIEventsListeners
{
private:
	/* data */
public:
	mmSSAIEventListener(){
	}
	
  void onAdCueTimelineAdded(vector<mmAd> ssaiAdInfoTimeline){
		cout << "onAdCueTimelineAdded Callback";
    		cout<<" Ad ID = "<<ssaiAdInfoTimeline[0].getAdId()<<endl;
    		cout<<" Ad Title = "<<ssaiAdInfoTimeline[0].getAdTitle()<<endl;
    		cout<<" Ad Duration = "<<ssaiAdInfoTimeline[0].getAdDuration()<<endl;
    		cout<<" Ad adStartPosition = "<<ssaiAdInfoTimeline[0].getAdStartPosition()<<endl;
    		cout<<" Ad adEndPosition = "<<ssaiAdInfoTimeline[0].getAdEndPosition()<<endl;
    		cout<<" Ad adStartTime = "<<ssaiAdInfoTimeline[0].getAdStartTime()<<endl;
    		cout<<" Ad adEndTime = "<<ssaiAdInfoTimeline[0].getAdEndTime()<<endl;
	}

  void onAdCueTimelineEnter(mmAd ssaiAdInfo){
		cout << "onAdCueTimelineEnter Callback";
	}

  void onAdCueTimelineExit(mmAd ssaiAdInfo){
		cout << "onAdCueTimelineExit Callback";
	}

  void onAdImpression(mmAd ssaiAdInfo) {
  		cout<<" Ad adStartTime = "<<ssaiAdInfo.getAdStartTime()<<endl;
    		cout<<" Ad adEndTime = "<<ssaiAdInfo.getAdEndTime()<<endl;
    
		cout << "onAdImpression Callback";
	}

  void onAdStarted(mmAd ssaiAdInfo) {
		cout << "onAdStarted Callback";
	}

  void onAdFirstQuartile(mmAd ssaiAdInfo){
		cout << "onAdFirstQuartile Callback";
	}

  void onAdMidpoint(mmAd ssaiAdInfo){
		cout << "onAdMidpoint Callback";
	}

  void onAdThirdQuartile(mmAd ssaiAdInfo){
		cout << "onAdThirdQuartile Callback";
	}

  void onAdComplete(mmAd ssaiAdInfo){
		cout << "onAdComplete Callback";
	}
	
  void onAdError(mmAd ssaiAdInfo){
		cout << "onAdError Callback";
	}
};

Handling Trick Play Scenarios: The callback associated with the onAdCueTimelineEnter can be employed to signal the video player to disable the seek bar, thereby preventing the ad from being skipped. Correspondingly, upon conclusion of the ad break, the video player will receiveonAdCueTimelineExit, prompting the enable of the seek bar.

void onAdCueTimelineEnter(mmAd ssaiAdInfo){
    //Event dispatched for Ad break started
    //playerObject.disableSeek();
}

void onAdCueTimelineExit(mmAd ssaiAdInfo){
    //Event dispatched for Ad break ended
    //playerObject.enableSeek();
}

Step5: Ad Playback Error

When an ad playback error occurs, call the function named signalAdPlaybackError() from the sample application. Calling this function will trigger the onAdError callback which contains the ad data.

adManager->signalAdPlaybackError();

Step6: Stop SSAI Ad Manager

To stop the SSAI Ad Manager, call the function named stopSSAIAdManager() from the sample application. Calling this function will stop the manifest and vast network calls as well.

adManager->stopSSAIAdManager();
Variable
Description

mediaUrl

String containing the media URL.

vastUrl

String containing the vast URL for live streams. For VoD, it should be an empty string.

isLive

A boolean variable. It should be true for live streams and false for VoD streams.

json_VOD_response

VoD stream curl response in JSON format. It should be Empty JSON object for live streams.

playheadPosition

int64 value containing absolute playhead position of the stream playing.

Last updated