Getting Started

The ExoPlayer v2 SDK is currently available as a beta release.

Include the Mux SDK for your project by downloading the AAR from our GitHub repo and including it in your project.

We recommend using Android Studio's new module tool which can be accessed via File > New > New Module.... Select the Import .JAR/.AAR Package and then select the mux.arr that you downloaded from our GitHub repo. This should correctly configure the IDE as well as modify your build configuration (Gradle/Maven).

For an example integration, you can see this commit on GitHub which integrates Mux into the ExoPlayer demo application.

After importing the AAR, you'll need to modify a few pieces of your ExoPlayer integration:

1) Create the CustomerPlayerData and CustomerVideoData objects as appropriate for your current playback, and be sure to set your property key.

import com.mux.stats.core.models.CustomerPlayerData;
import com.mux.stats.core.models.CustomerVideoData;
CustomerPlayerData customerPlayerData = new CustomerPlayerData();
CustomerVideoData customerVideoData = new CustomerVideoData();
customerVideoData.setVideoTitle("The most epic video ever");

2) Create the MuxStats object by passing the ExoPlayer instance, a player name and the customer data objects.

import com.mux.stats.sdk.muxstats.MuxStats;
muxStats = new MuxStats(player, "demo-player", customerPlayerData, customerVideoData);

3) In order to correctly monitor if the player is full-screen, provide the screen size to the MuxStats instance.

Point size = new Point();
muxStats.setScreenSize(size.x, size.y);

4) In order to determine a number of viewer context values as well as track the size of the video player, set the player view.


5) Next, we need to attach all the appropriate listeners to the player as well as all of your ChunkSource and MediaSource objects. There are two things that we are need to consider. First, there is no built in chaining of listeners meaning that if you already have listeners attached you will need to use the get*EventListener(*EventListener):*EventListener function to wrap your exisiting listener. Second, there is no base-class for these listeners which means that each object requires a different listener to be attached. Failure to attach the MuxStats listeners to all appropriate objects will result in at least partially broken integration.

Note that MuxStats will call ExoPlayer.addListener(EventListener) itself.

// getAudioRendererEventListener():AudioRendererEventListener also exists.

// getVideoRendererEventListener():VideoRendererEventListener also exists.

// getMetadataRendererOutput():Output also exists.

// A couple ChunkSource/MediaSource examples.

// getAdaptiveMediaSourceEventListener():AdaptiveMediaSourceEventListener also exists.
new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler,

// getExtractorMediaSourceEventListener():EventListener also exists.
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
    mainHandler, muxStats.getExtractorMediaSourceEventListener(eventLogger));

6) Finally, when you are destroying the player, call the MuxStats.release() function.

Confirming it works

After you've integrated, start playing a video in the player you've integrated with. Then for your viewing session (called a "video view") to show up in the Mux dashboard, you need to stop watching the video. In a few minutes you'll see the results in your Mux account. We'll also email you when the first video view has been recorded.