Monitor Android MediaPlayer | Mux
Monitor Android MediaPlayer
Connect Mux Data to the Android MediaPlayer class to collect playback performance metrics. Use this guide when your Android application plays video with MediaPlayer.
In this guide:
Features
The features supported by Mux Data for this player.
1 Install the Mux Data SDK
Download the latest version of Mux Stats MediaPlayer AAR.
2 Initialize the monitor with your MediaPlayer instance
Attach MuxMediaPlayer to your player so that Mux can collect playback metrics.
3 Set up required events
Set up required events so that MuxMediaPlayer can hook into the underlying player behavior.
4 Make your data actionable
Use metadata fields to make the data collected by Mux actionable and useful.
5 Advanced options
Depending on the details of your implementation, you may want to leverage some of the advanced options of mux-embed.
Features
The following data can be collected by the Mux Data SDK when you use the Android Media Player SDK, as described below.
Supported Features:
- Engagement metrics
- Quality of Experience Metrics
- Available for deployment from a package manager
Notes:
Video Quality metrics are not available.
1 Install the Mux Data SDK
The easiest way to get the AAR is to download the latest version from: muxinc/mux-stats-sdk-mediaplayer releases.
If you would prefer to build it yourself, first clone the repo. Then, you can do one of the following:
- Open the project in Android Studio and build the release variant of the
MuxMediaPlayermodule. You can then find the AAR inmux-stats-sdk-mediaplayer/MuxMediaPlayer/build/outputs/aar/MuxMediaPlayer-release.aar - Build the AAR directly:
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.aar that you downloaded or built. This should correctly configure the IDE as well as modify your build configuration (Gradle/Maven).
For an example integration, you can see the demo application within this repo which integrates Mux into the MediaPlayer demo application.
2 Initialize the monitor with your MediaPlayer instance
Get your ENV_KEY from the Mux environments dashboard.
First, create the CustomerPlayerData and CustomerVideoData objects as appropriate for your current playback, and be sure to set your ENV_KEY.
Next, create the MuxStatsMediaPlayer object by passing your Android Context (typically your Activity), the MediaPlayer instance, a player name, and the customer data objects.
To allow MuxStatsMediaPlayer to listen for various MediaPlayer events, add it as a listener. MediaPlayer only allows single listeners, so if your activity or application also needs to listen to these events, use the helper methods to wrap your listener implementation with MuxStatsMediaPlayer's listener implementation.
Finally, when you are destroying the player, call the MuxStatsMediaPlayer.release() method.
3 Set up required events
MediaPlayer does not provide listener callbacks for all necessary events, so you must add explicit calls into MuxStatsMediaPlayer at the same time that certain MediaPlayer methods are invoked:
startpauseseekTo
4 Make your data actionable
In the MediaPlayer SDK, options are provided via the CustomerPlayerData and CustomerVideoData objects.
All metadata details except for envKey are optional; however, you'll be able to compare and see more interesting results as you include more details.
5 Advanced options
Changing the video
When you change to a new video (in the same player) you need to update the information that Mux knows about the current video. Examples of when this is needed are:
- The player advances to the next video in a playlist
- The user selects a different video to play
Error tracking
By default, Mux's integration with MediaPlayer automatically tracks fatal errors as thrown by MediaPlayer. In some applications, however, you may want to disable this and track errors on your own, especially if you have retry logic in your application to try to recover from errors that MediaPlayer encounters.
Release notes
Current release
v0.1.0
- Initial integration with MediaPlayer