MediaMelon
  • MediaMelon SDK Integration
  • MediaMelon SDK Events
  • MediaMelon Player SDK Integration
    • React Native
      • React Native Video v5.2.0 with Mediamelon SDK
      • React Native Video v6.4.2 with Mediamelon SDK
    • Web SDK
      • VideoJS Web with Mediamelon Analytics
      • VideoJS Web with Google DAI
      • Shaka Player Web v4
      • MediaMelon Web Kaltura Player Plugin Integration Document
      • NexPlayer Web v4
      • THEOPlayer Web
      • JWPlayer Web
      • Radiant Player Web
      • ChromeCast Player
      • HLSJS Player Web
      • HbbTV SDK
      • Comcast PDK 6
      • Bitmovin Web Player
      • HTML5 Player Web
      • Flow Player Web
      • DashJS Player Web
      • Castlabs Player Web
      • Cordova Plugin Toast (Smart TV)
      • Custom Player Web SDK
      • Plyr Player Web with MediaMelon Analytics
      • React Player SDK with IMA
    • Android SDK
      • App Analytics SDK
      • Bitmovin Android v3.73 with Content Provider Metrics
      • Exoplayer v2.13.2 integration with MediaMelon SDK
      • Exoplayer v2.17.1 with Mediamelon SDK
      • Exoplayer v2.12.2 integration with MediaMelon SDK
      • EXOPlayer-Android(V2.14.2) MediaMelon SDK with Google IMA DAI
      • EXOPlayer-Android(V2.17.1) MediaMelon SDK with Google IMA DAI
      • Exoplayer v2.11
      • Exoplayer v2.18.1 with Mediamelon SDK
      • Theoplayer v6.0.0 with Mediamelon SDK
      • Theoplayer v4.12.6 with Mediamelon SDK
      • Theoplayer v7.5.0 with Mediamelon SDK
      • Exoplayer v2.13.3 integration with MediaMelon SDK
      • Kaltura Android Player Integration with Mediamelon SDK
      • Media3 v1.3.0 and ExoPlayer 2.19.1 with MediaMelon SDK
      • Media3 v1.3.1 with MediaMelon SDK
      • MediaMelon Android Media3 v1.1.1 SDK Integration Document
      • Media3Player-Android(V1.3.0) MediaMelon SDK with Google IMA
    • Roku SDK
      • Roku SDK
      • Roku with RAF SDK
      • Roku with IMA SDK
    • iOS SDK
      • AVPlayer (Cocoapods)
      • AVPlayer with Google DAI SDK ( Framework )
      • AVPlayer Quality Of Experience SDK
      • AVPlayer Generic Framework
      • AVPlayer with Google DAI (Cocoapods)
      • Bitmovin iOS v3.44 with Content Provider Metrics
      • THEOPlayer XCFramework
      • THEOplayer (Cocoapods)
      • MediaMelon iOS Kaltura Player Plugin Integration Document
    • tvOS SDK
      • AVPlayer tvOS XCFramework
      • THEOPlayer tvOS XCFramework
    • Toast SDK
    • Custom Player C++ SDK
    • C++ SDK QoE Ads
    • Ad Integrations
      • Google IMA
      • FreeWheel
      • ServerSide.AI
  • SmartSight Analytics
    • Product Features
    • QBR Streaming
  • SmartSight API's
    • API Overview
      • Metric and Dimensions Dictionary
      • General Guidelines
      • Video Experience
      • Ad Experience
      • Smartquery Insights
      • Errors
      • Alerts
    • Use-case dictionary
Powered by GitBook
On this page
  • Prerequisites
  • Step 1: Set up the build environment
  • Step 2: Register SDK
  • Step 3: Initialize Session & Report User Intent to Playback
  • Step 4: Report User Intent to Playback
  • Step 5: Report ended state when the player instance is released

Was this helpful?

  1. MediaMelon Player SDK Integration
  2. Android SDK

Exoplayer v2.11

This guide is for integrating MediaMelon SDK with Exoplayer v2.11.0 - v2.11.8

PreviousEXOPlayer-Android(V2.17.1) MediaMelon SDK with Google IMA DAINextExoplayer v2.18.1 with Mediamelon SDK

Last updated 1 year ago

Was this helpful?

This guide uses Exoplayer 2.11.4 as a reference. Please replace with the correct version of v2.11 player

Prerequisites

  1. ExoPlayer-r2.11.4

  2. MediaMelon SmartSight SDK smartstreaming.aar

Step 1: Set up the build environment

Note $EXOPROJECT = {ExoPlayer-r2.11.4}

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.

You can check SDK registration status with getRegistrationStatus(). If the registration is not complete, use the registerMMSmartStreaming() to complete the registration.

Step 2a: Import packages

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

// <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 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();
    clearStartPosition();
  }

  //<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.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

@Nullable
  private MediaSource createTopLevelMediaSource(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();
      return null;
    }

    Sample intentAsSample = Sample.createFromIntent(intent);
    UriSample[] samples =
        intentAsSample instanceof Sample.PlaylistSample
            ? ((Sample.PlaylistSample) intentAsSample).children
            : new UriSample[] {(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);
        return null;
      }
      if (Util.maybeRequestReadExternalStoragePermission(/* activity= */ this, sample.uri)) {
        // The player will be reinitialized if the permission is granted.
        return null;
      }
    }

    MediaSource[] mediaSources = new MediaSource[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.
          return null;
        }
        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] = new MergingMediaSource(mediaSources[i], subtitleMediaSource);
      }
    }
    MediaSource mediaSource =
        mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(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

// Internal methods

  private void initializePlayer() {
    if (player == null) {
      Intent intent = getIntent();
      // <MMSmartStreaming 4> Integration start Comment below lines 
      //mediaSource = createTopLevelMediaSource(intent);
      //if (mediaSource == null) {
      //  return;
      //}
      // </MMSmartStreaming 4> Integration end
      
      TrackSelection.Factory trackSelectionFactory;
      String abrAlgorithm = intent.getStringExtra(ABR_ALGORITHM_EXTRA);
      if (abrAlgorithm == null || ABR_ALGORITHM_DEFAULT.equals(abrAlgorithm)) {
        trackSelectionFactory = new AdaptiveTrackSelection.Factory();
      } else if (ABR_ALGORITHM_RANDOM.equals(abrAlgorithm)) {
        trackSelectionFactory = new RandomTrackSelection.Factory();
      } else {
        showToast(R.string.error_unrecognized_abr_algorithm);
        finish();
        return;
      }

      boolean preferExtensionDecoders =
          intent.getBooleanExtra(PREFER_EXTENSION_DECODERS_EXTRA, false);
      RenderersFactory renderersFactory =
          ((DemoApplication) getApplication()).buildRenderersFactory(preferExtensionDecoders);

      trackSelector = new DefaultTrackSelector(/* context= */ this, trackSelectionFactory);
      trackSelector.setParameters(trackSelectorParameters);
      lastSeenTrackGroupArray = null;

      player =
          new SimpleExoPlayer.Builder(/* context= */ this, renderersFactory)
              .setTrackSelector(trackSelector)
              .build();
      player.addListener(new PlayerEventListener());
      player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */ true);
      player.setPlayWhenReady(startAutoPlay);
      player.addAnalyticsListener(new EventLogger(trackSelector));
      playerView.setPlayer(player);
      playerView.setPlaybackPreparer(this);
      debugViewHelper = new DebugTextViewHelper(player, debugTextView);
      debugViewHelper.start();
      if (adsLoader != null) {
        adsLoader.setPlayer(player);
      }
      // <MMSmartStreaming 4> Integration start Add below lines
      mediaSource = createTopLevelMediaSource(intent);
      if (mediaSource == null) {
        return;
      }
      // </MMSmartStreaming 4> Integration end
    }
    boolean haveStartPosition = startWindow != C.INDEX_UNSET;
    if (haveStartPosition) {
      player.seekTo(startWindow, startPosition);
    }
    // <MMSmartStreaming 4> Integration Start (User playback Loaded)
    MMSmartStreamingExo2.getInstance().reportUserInitiatedPlayback();
    // </MMSmartStreaming 4> Integration end
    player.prepare(mediaSource, !haveStartPosition, false);
    updateButtonVisibility();
  }

Step 5: 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) {
      updateTrackSelectorParameters();
      updateStartPosition();
      debugViewHelper.stop();
      debugViewHelper = null;
      player.release();
      player = null;
      mediaSource = null;
      trackSelector = null;
       // <MMSmartStreaming 5> Start
	  MMSmartStreamingExo2.getInstance().reportPlayerState(false, Player.STATE_ENDED);
	  // </MMSmartStreaming 5> End
    }
    if (adsLoader != null) {
      adsLoader.setPlayer(null);
    }
  }
https://github.com/google/ExoPlayer