EXOPlayer-Android(V2.14.2) MediaMelon SDK with Google IMA DAI
This procedure describes the MediaMelon SDK(with Google IMA DAI) Integration with a ExoPlayer Android . This is a sample integration done with the sample application from the Google IMA DAI.
Step 2.2 :
Add the below imports to: BasicExample\app\src\main\java\com\google\ads\interactivemedia\v3\samples\samplevideoplayer/SampleVideoPlayer.java
Step 3 : Integrate MediaMelon code to the Sample App
The below steps shows the procedure to integrate the MediaMelon library to the sample app.
Note - Only the code written inside the <MediaMelon Integration> tag is to be added for MediaMelon specific integration , the rest of the code above and below the <MediaMelon Integration> tag is shown just to give a context ,as shown below :-
<MediaMelon Integration>CodeforMediaMelon specific integration<//MediaMelon Integration>
Step 3.1:
Add the following code to:
BasicExample\app\src\main\java\com\google\ads\interactivemedia\v3\samples\samplevideoplayer/SampleVideoPlayer.java
privatevoidinitPlayer() { // this is the function that creates/initialises the EXO playerrelease(); simpleExoPlayer =new SimpleExoPlayer.Builder(context).build();playerView.setPlayer(simpleExoPlayer);....<MediaMelon Integration>String assetId ="assetID"; //enter you assetId hereString assetName ="assetNAME"; // enter your assetname hereString videoId ="videoID"; // enter your videoId here//optional content metadataContentMetadata cm =newContentMetadata();String episodeNumber ="$episodeNumber ";String season ="$season";String genre ="$genre";String drmProtection ="$drmProtection";String contentType ="$contentType";String title ="$title";String videoType ="$videoType";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;cm.videoType= videoType;JSONObject ContentMetadataAsJSON =cm.getJSONObject();//the below initializeSession() call is to be made only after the EXO player instance has been createdMMSmartStreamingExo2.getInstance().initializeSession(simpleExoPlayer,MMQBRMode.QBRModeDisabled,"$streamUrl",null,assetId,assetName,videoId,null,ContentMetadataAsJSON);//(optional) add custom tagsMMSmartStreamingExo2.getInstance().reportCustomMetadata("key","value");MMSmartStreamingExo2.getInstance().reportUserInitiatedPlayback();<//MediaMelon Integration>};
Step 3.2:
Add the following code to:
BasicExample\app\src\main\java\com\google\ads\interactivemedia\v3\samples\videoplayerapp/MyActivity.java
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_my);....<MediaMelon Integration>Log.d("SmartStreamingIntgr",MMSmartStreamingExo2.getVersion());MMSmartStreamingExo2.enableLogTrace(true); //set to "false" before releasing player to productionif (MMSmartStreamingExo2.getRegistrationStatus() ==false){ //Check if it is the first time Registration process is doneMMSmartStreamingExo2.registerMMSmartStreaming("$PLAYERNAME","$CustomerId","$SUBSCRIBERID","$DOMAINNAME","$SUBSCRIBERTYPE","$SUBSCRIBERTAG");MMSmartStreamingExo2.reportPlayerInfo("$Brand","$Model","$Version");MMSmartStreamingExo2.getInstance().setContext(getApplicationContext()); //Please make sure to provide the application's context here, and not the activity's context }<//MediaMelon Integration>.... }
Variable
Description
$PLAYERNAME
String containing the player version (e.g. “Bitmovin_Android_Player_2.28.0”).
$CUSTOMERID
String containing your MediaMelon-assigned Customer ID.
$SUBSCRIBERID
String containing your subscriber’s ID. If you do not use subscriber IDs, enter null
$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, enter null
$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.
$ASSETID
String containing Asset Id.
$ASSETNAME
String containing Asset Name.
$VIDEOID
String containing your video’s ID. If you do not use videos IDs, enter null.
$PLAYER_BRAND
String containing the player brand (e.g. “bitmovin”).
$PLAYER_MODEL
String containing the player model. For example - This could be a variant of player. Say name of third party player used by organisation. Or any human readable name of the player.
$PLAYER_VERSION
String containing the player version.
Step 3.3 :
Add the following code to:
BasicExample\app\src\main\java\com\google\ads\interactivemedia\v3\samples\videoplayerapp/SampleAdsWrapper.java
privatefinalImaSdkFactory sdkFactory;privateAdsLoader adsLoader;privateStreamDisplayContainer displayContainer;privateStreamManager streamManager;privatefinalList<VideoStreamPlayer.VideoStreamPlayerCallback> playerCallbacks;..<MediaMelon Integration>MMAnalyticsBridge analyticsBridgeObject; // Declaration of Analytics Bridge object , wherever the IMA AdsLoader and IMA StreamManager are declared in your application<//MediaMelon Integration>
privatevoidcreateAdsLoader() { // this functions creates the Google IMA DAI ads loader (which is preferably a singleton - only one ads loader for the entire lifecyle)ImaSdkSettings settings =sdkFactory.createImaSdkSettings();<MediaMelon Integration> analyticsBridgeObject =MMSmartStreamingExo2.getInstance().getAnalyticsBridge(); // get the Analytics Bridge Object ,this should be done wherever in your application the Google IMA adsLoader is created<//MediaMelon Integration>... adsLoader =sdkFactory.createAdsLoader(context, settings, displayContainer);}
publicvoidrequestAndPlayAds() { ..<MediaMelon Integration>adsLoader.addAdErrorListener(analyticsBridgeObject); // pass the Analytics Bridge object to the ads error listenersadsLoader.addAdsLoadedListener(analyticsBridgeObject); // pass the Analytics Bridge object to the ads loaded listeners<//MediaMelon Integration>..adsLoader.addAdErrorListener(this);adsLoader.addAdsLoadedListener(this); adsLoader.requestStream(buildStreamRequest());..}
@OverridepublicvoidonAdsManagerLoaded(AdsManagerLoadedEvent event) {..<MediaMelon Integration>streamManager.addAdErrorListener(analyticsBridgeObject); // pass the Analytics Bridge object to the ad error listenersstreamManager.addAdEventListener(analyticsBridgeObject); // pass the Analytics Bridge object to the ad event listeners<//MediaMelon Integration>..streamManager.addAdErrorListener(this);streamManager.addAdEventListener(this);streamManager.init();.. }
@OverridepublicvoidonAdEvent(AdEvent event) { // this is a callback which gets called whenever a AD event occursswitch (event.getType()) {// Access all ad events here , this method will be automatically called whenever an ad event occurscase AD_PROGRESS:// write your own logic inside each casebreak;case FIRST_QUARTILE:// write your own logic inside each casebreak;case MIDPOINT:// write your own logic inside each casebreak;case THIRD_QUARTILE:// write your own logic inside each casebreak;case COMPLETED:// write your own logic inside each casebreak;default:log(String.format("Event: %s\n",event.getType()));break; } }