Media3 v1.3.1 with MediaMelon SDK

This guide is for integrating MediaMelon SDK with Media3 v1.3.1

Prerequisites

  • Meida3 - v1.3.1 sample application.

  • MediaMelon SmartSight SDK Maven dependencies or the provided smartstreaming_release.aar AAR file is necessary.

Step 1: Set up the build environment

$MEDIA3PROJETC = {Media3 - v1.3.1}

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

Using Maven:

  1. Add MediaMelon Maven dependency to $MEDIA3PROJETC/demos/main/build.gradle

    dependencies {
       ...
      //<!-- <MMSmartStreaming 1b> -->
      implementation 'com.github.MediamelonSDK:mm-sdk-media-3-android:1.0.0'
      implementation 'androidx.media3:media3-exoplayer:1.3.1'
      //<!-- </MMSmartStreaming 1b> --> 
    }

Using AAR:

  1. Copy smartstreaming-release.aar provided with the release package to the Media3 project. Example $MEDIA3PROJETC/demos/main/smartstreaming-release.aar

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

dependencies {
  ...
  //<!-- <MMSmartStreaming 1b> -->
  api files ('smartstreaming-release.aar')
  implementation 'com.github.MediamelonSDK:mm-sdk-media-3-android:1.0.0'
  //<!-- </MMSmartStreaming 1b> --> 
}

Add network permissions to $MEDIA3PROJETC/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 2: Import packages

$MEDIA3PROJETC/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java

// <MMSmartStreaming 2a>
import com.mediamelon.qubit.ep.ContentMetadata;
import com.mediamelon.smartstreaming.MMQBRMode;
import com.mediamelon.smartstreaming.media3.MMSmartStreamingExo3;
// </MMSmartStreaming 2a>

Step 3: Registration, Initialize Session & Report User Intent to Playback

The player application must register the SDK and provide player information once after player is initialized. Please note that values provided in this integration step persist across video sessions.

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.

  • Set the isLive variable in initializeSession() call , set true for live stream else false.

The enableLogTrace() feature should be enabled for testing during the integration process. Set this to False before releasing the player to production

protected boolean initializePlayer() {
   if (player == null) {
   Intent intent = getIntent();
   ...
   // after player is initialised and not null anymore
   initializeMediaMelon();
   ...
 }

void initializeMediaMelon(){
    // <MMSmartStreaming 3>
     MMSmartStreamingExo3.enableLogTrace(true); //set to "false" before releasing player to production
    if (MMSmartStreamingExo3.getRegistrationStatus() == false)
    { //Check if it is the first time Registration process is done

      MMSmartStreamingExo3.setContext(getApplicationContext()); //Please make sure to provide the application's context here, and not the activity's context
      MMSmartStreamingExo3.registerMMSmartStreaming("PLAYER_NAME", "customerID", "SUBSCRIBER_ID", "DOMAIN_NAME", "SUBSCRIBER_TYPE", "SUBSCRIBER_TAG",false);
      MMSmartStreamingExo3.reportPlayerInfo("PLAYEER_Brand", "PLAYER_MODEL", "PLAYER_VERSION");
      MMSmartStreamingExo3.reportAppInfo("APP_NAME","APP_VERSION");
      MMSmartStreamingExo3.reportVideoQuality("VIDEO_QUALITY");
      MMSmartStreamingExo3.setDeviceInfo("DEVICE_MARKETING_NAME");
    }
    //MM
    String mediaUrl = String.valueOf(mediaItems.get(0).localConfiguration.uri); //getting the mediaURL from the application

    ContentMetadata cm  = new ContentMetadata();
    cm.assetName="ASSET_NAME";
    cm.assetId="ASSET_ID";
    cm.videoId="VIDEO_ID";
    cm.seriesTitle="SERIES_TITLE";
    cm.season="SEASON";
    cm.genre="GENRE";
    cm.episodeNumber="EPISODE_NUMBER";
    cm.drmProtection="DRM_PROTECTION";
    cm.contentType="CONTENT_TYPE";
    JSONObject contentMetadata = cm.getJSONObject();

    MMSmartStreamingExo3.reportCustomMetadata("KEY1","VALUE1");
    MMSmartStreamingExo3.initializeSession(player,MMQBRMode.QBRModeDisabled, mediaUrl, null, null,contentMetadata,false);
    MMSmartStreamingExo3.reportUserInitiatedPlayback();
    // <MMSmartStreaming 3>
 }

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

In $MEDIA3PROJETC/demos/main/src/main/java/androidx/media3/demo/main/PlayerActivity.java

private void releasePlayer() {
    if (player != null) {
      updateTrackSelectorParameters();
      updateStartPosition();
      debugViewHelper.stop();
      debugViewHelper = null;
      player.release();
      player = null;
      mediaSource = null;
      trackSelector = null;
      // <MMSmartStreaming 4> Start
      MMSmartStreamingExo3.reportPlayerState(false, Player.STATE_ENDED);
      // </MMSmartStreaming 4> End
    }
  }

Last updated