Exoplayer v2.13.2 integration with MediaMelon SDK


Step 1: Set up the build environment

Note $EXOPROJECT = {ExoPlayer-r2.13.2}

The SDK files are added to the build environment and the required network permissions are enabled.

  1. Copy smartstreaming-release.aar provided with the release package to the exoplayer project, Example $EXOPROJECT/demos/main/smartstreaming-release.aar

  2. Add the following library to $EXOPROJECT/demos/main/build.gradle :-

dependencies {
   //<!-- <MMSmartStreaming 1b> -->
    api files ('smartstreaming-release.aar')
  //<!-- </MMSmartStreaming 1b> -->

Add network permissions to $EXOPROJECT/demos/main/src/main/AndroidManifest.xml

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

<!-- <MMSmartStreaming 1c> -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- </MMSmartStreaming 1c> -->

Step 2: 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.

Step 2a: Import packages


// <MMSmartStreaming 2a>
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.mediamelon.smartstreaming.MMQBRMode;
import com.mediamelon.smartstreaming.MMSmartStreaming;
import com.mediamelon.smartstreaming.MMSmartStreamingExo2;
import com.mediamelon.smartstreaming.MMSmartStreamingInitializationStatus;
import com.mediamelon.smartstreaming.MMSmartStreamingObserver;
import com.mediamelon.qubit.ep.ContentMetadata;
import java.util.ArrayList;
import android.util.Log;
// </MMSmartStreaming 2a>

Step 2b: 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

public void onCreate(Bundle savedInstanceState) {
  }else {
    trackSelectorParameters = new DefaultTrackSelector.ParametersBuilder().build();

  //<MMSmartStreaming 2b>
  Log.d("SmartStreamingIntgr", MMSmartStreamingExo2.getVersion());
  MMSmartStreamingExo2.enableLogTrace(true); //set to "false" before releasing player to production
  if (MMSmartStreamingExo2.getRegistrationStatus() == false)

{ //Check if it is the first time Registration process is done

    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
 MMSmartStreamingExo2.disableManifestsFetch(true); // pass true if you want to disable Manifests Fetch 
  // </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.

protected boolean initializePlayer() {
if (player == null) {
Intent intent = getIntent();

// 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";
    JSONObject contentMetadata = cm.getJSONObject();
    //optional content metadata
    //(optional) add custom tags
    MMSmartStreamingExo2.getInstance().initializeSession(player, MMQBRMode.QBRModeDisabled, mediaUrl, null, assetId, assetName, videoId,null,contentMetadata);

Step 4: Report ended state when the player instance is released

In $EXOPROJECT/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java

private void releasePlayer() {
    if (player != null) {
      debugViewHelper = null;
      player = null;
      mediaSource = null;
      trackSelector = null;
       // <MMSmartStreaming 5> Start
	  MMSmartStreamingExo2.getInstance().reportPlayerState(false, Player.STATE_ENDED);
	  // </MMSmartStreaming 5> End
    if (adsLoader != null) {

Last updated