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.
You can check SDK registration status with getRegistrationStatus(). If the registration is not complete, use the registerMMSmartStreaming() to complete the registration.
Perform registration tasks by modifying the onCreate() method in $EXOPROJECT/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
The enableLogTrace() feature should be enabled for testing during the integration process. Set this to False before releasing the player to production
publicvoidonCreate(Bundle savedInstanceState) {... }else { trackSelectorParameters =new DefaultTrackSelector.ParametersBuilder().build();clearStartPosition(); }//<MMSmartStreaming 2b>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 done MMSmartStreamingExo2.registerMMSmartStreaming($PLAYERNAME, $CUSTOMERID, $SUBSCRIBERID, $DOMAINNAME, $SUBSCRIBERTYPE, $SUBSCRIBERTAG);
MMSmartStreamingExo2.reportPlayerInfo("CustomPlayerName",ExoPlayerLibraryInfo.VERSION,"1.0"); MMSmartStreamingExo2.getInstance().setContext(getApplicationContext()); //Please make sure to provide the application's context here, and not the activity's context
}// </MMSmartStreaming 2b> }
Step 3: Initialize Session & Report User Intent to Playback
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.
Provide application context to SDK by modifying the createTopLevelMediaSource() method in $EXOPROJECT/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
@NullableprivateMediaSourcecreateTopLevelMediaSource(Intent intent) {String action =intent.getAction();boolean actionIsListView =ACTION_VIEW_LIST.equals(action);if (!actionIsListView &&!ACTION_VIEW.equals(action)) {showToast(getString(R.string.unexpected_intent_action, action));finish();returnnull; }Sample intentAsSample =Sample.createFromIntent(intent);UriSample[] samples = intentAsSample instanceofSample.PlaylistSample? ((Sample.PlaylistSample) intentAsSample).children:newUriSample[] {(UriSample) intentAsSample};boolean seenAdsTagUri =false;for (UriSample sample : samples) { seenAdsTagUri |=sample.adTagUri!=null;if (!Util.checkCleartextTrafficPermitted(sample.uri)) {showToast(R.string.error_cleartext_not_permitted);returnnull; }if (Util.maybeRequestReadExternalStoragePermission(/* activity= */this,sample.uri)) {// The player will be reinitialized if the permission is granted.returnnull; } }MediaSource[] mediaSources =newMediaSource[samples.length];for (int i =0; i <samples.length; i++) { mediaSources[i] =createLeafMediaSource(samples[i]);Sample.SubtitleInfo subtitleInfo = samples[i].subtitleInfo;if (subtitleInfo !=null) {if (Util.maybeRequestReadExternalStoragePermission(/* activity= */this,subtitleInfo.uri)) {// The player will be reinitialized if the permission is granted.returnnull; }Format subtitleFormat =Format.createTextSampleFormat(/* id= */null,subtitleInfo.mimeType,C.SELECTION_FLAG_DEFAULT,subtitleInfo.language);MediaSource subtitleMediaSource =new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(subtitleInfo.uri, subtitleFormat,C.TIME_UNSET); mediaSources[i] =newMergingMediaSource(mediaSources[i], subtitleMediaSource); } }MediaSource mediaSource =mediaSources.length==1? mediaSources[0] :newConcatenatingMediaSource(mediaSources);// //<MMSmartStreaming 3> Integration start ------if(mediaSources.length>0 ){String mediaUrl = samples[0].uri.toString(); MMSmartStreamingExo2.getInstance().initializeSession(player, $QBRREQUESTEDMODE, mediaUrl, $ASSETMETAURL, "ASSETID", "ASSETNAME", "VIDEOID", null);
}// //</MMSmartStreaming 3> Integration end -------if (seenAdsTagUri) {Uri adTagUri = samples[0].adTagUri;if (actionIsListView) {showToast(R.string.unsupported_ads_in_concatenation); } else {if (!adTagUri.equals(loadedAdTagUri)) {releaseAdsLoader(); loadedAdTagUri = adTagUri; }MediaSource adsMediaSource =createAdsMediaSource(mediaSource, adTagUri);if (adsMediaSource !=null) { mediaSource = adsMediaSource; } else {showToast(R.string.ima_not_loaded); } } } else {releaseAdsLoader(); }return mediaSource; }
Please note line number 55-60 is where MediaMelon code is added
Step 4: Report User Intent to Playback
When the user presses the play button for the first time to start the playback, or in autoplay mode when a player is fed with a content URL to load the session, reportUserInitiatedPlayback() should be called. In the demo application, autoplay is “on”, so let's call this API just before player.prepare()
In $EXOPROJECT/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java