Monitor AndroidX Media3
FastPix Data SDK for AndroidX Media3 (latest version of ExoPlayer) helps you track key video metrics like user interactions, playback quality, and performance to enhance the viewing experience. It lets you customize data tracking, monitor streaming quality, and securely send insights for better optimization and error resolution.
Key features:
- Capture user engagement through detailed viewer interaction data.
- Monitor playback quality with real-time performance analysis.
- Identify and fix video delivery bottlenecks on Android.
- Customize tracking to match specific monitoring needs.
- Handle errors with robust reporting and diagnostics.
Step 1
Installation and setup
Step 2
Import the SDK
Step 3
Basic integration
Step 4
Including metadata
Step 5
Advanced configuration
Step 6
Emit custom events
Detailed example
Configure Media3
PREREQUISITES
- To track and analyze video performance, initialize the FastPixVideo Data SDK with your Workspace key. This key is essential for client-side monitoring and must be included in your Android application's code wherever you want to track video performance.
- An existing Android Studio project where you plan to integrate the Video Data SDK.
- Gradle configured in your project for managing dependencies.
- Media3 ExoPlayer pre-installed and integrated with your project for Video Data setup.
Step 1: Install and setup
-
Open your Android Studio project where you want to integrate the SDK.
-
Add the Video Data SDK dependency
Navigate to your app-level build.gradle file (or build.gradle.kts if using Kotlin DSL).
//Add the following line under the dependencies section: dependencies { // check with latest version implementation 'io.fastpix.data:media3:1.0.0 ' }
Navigate to your settings.gradle file
//Add the following lines inside repositories section: repositories { maven { url = uri("https://maven.pkg.github.com/FastPix/android-data-media3-player-sdk") credentials { // Your GitHub account username (or) FastPix username = "Github_User_Name" // Your (PAT) Personal access token Get It from you Github account password = "Github_PAT" } } }
-
Sync your project with Gradle files
Click "Sync Now" in the notification bar to download and integrate the FastPix Data SDK.
Once the above dependency is added, you can use the FastPix Data SDK module into your Android project where you intend to use its functionalities.
PLEASE NOTE
To ensure accurate analytics, initialize and complete the Media3 Exo-Player setup first. Once the player is fully ready, integrate and start the SDK in your project.
Step 2: Import the SDK
import io.fastpix.data.entity.*
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.request.CustomOptions
Step 3: Basic integration
Globally declare
You need to globally declare the ExoPlayer instance and FastPixBaseMedia3Player in your Android application. A global declaration ensures that these objects can be accessed throughout the lifecycle of your activity or application where required.
import ...
class VideoPlayerActivity : AppCompatActivity() {
private lateinit var exoPlayer: ExoPlayer // Global ExoPlayer instance
private lateinit var fastPixBaseMedia3Player: FastPixBaseMedia3Player // Global FastPix instance
}
You can initialize ExoPlayer with a PlayerView
or SurfaceView
in your Android application to enable seamless functionality. Use the following Kotlin or Java code in your Android application to configure Media3 ExoPlayer with FastPix:
import io.fastpix.data.entity.*
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.request.CustomOptions
class VideoPlayerActivity : AppCompatActivity() {
private lateinit var exoPlayer: ExoPlayer
private lateinit var fastPixBaseMedia3Player: FastPixBaseMedia3Player
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.your_layout) // don't forget this if needed
initializePlayers()
}
private fun initializePlayers() {
// Initialize Media3 ExoPlayer
exoPlayer = ExoPlayer.Builder(this).build()
val mediaItem = MediaItem.fromUri("https://your.video.url/here.mp4")
exoPlayer.setMediaItem(mediaItem)
exoPlayer.prepare()
// Prepare Customer Data
val customerPlayerDataEntity =
CustomerPlayerDataEntity().apply { workspaceKey = Constants.envKeyFp }
val customerVideoDataEntity =
CustomerVideoDataEntity().apply {
videoId = "Video ID"
videoTitle = "Video Title"
}
val customerViewDataEntity =
CustomerViewDataEntity().apply { viewSessionId = UUID.randomUUID().toString() }
val customDataEntity =
CustomDataEntity().apply {
customData1 = "Data 1"
customData2 = "Data 2"
// ...
customData10 = "Data 10"
}
val customerDataEntity =
CustomerDataEntity(
customerPlayerDataEntity,
customerVideoDataEntity,
customerViewDataEntity
)
.apply { setCustomData(customDataEntity) }
// Initialize FastPixBaseMedia3Player
fastPixBaseMedia3Player =
FastPixBaseMedia3Player(
this,
exoPlayer,
customerDataEntity,
CustomOptions() // Optional if your constructor allows default
)
fastPixBaseMedia3Player.setPlayerView(playerView) // replace with actual view binding
}
}
import io.fastpix.data.entity.CustomDataEntity;
import io.fastpix.data.entity.CustomerDataEntity;
import io.fastpix.data.entity.CustomerPlayerDataEntity;
import io.fastpix.data.entity.CustomerVideoDataEntity;
import io.fastpix.data.entity.CustomerViewDataEntity;
import io.fastpix.data.exo.FastPixBaseMedia3Player;
import io.fastpix.data.request.CustomOptions;
public class VideoPlayerActivity extends AppCompatActivity {
private ExoPlayer exoPlayer;
private FastPixBaseMedia3Player fastPixBaseMedia3Player;
// You’ll need to define this or use ViewBinding
private PlayerView playerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.your_layout); // Make sure this matches your
// layout XML
// Example: playerView = findViewById(R.id.player_view);
initializePlayers();
}
private void initializePlayers() {
// 1. Initialize ExoPlayer
exoPlayer = new ExoPlayer.Builder(this).build();
MediaItem mediaItem = MediaItem.fromUri("https://your.video.url/here.mp4");
exoPlayer.setMediaItem(mediaItem);
exoPlayer.prepare();
// 2. Customer Data
CustomerPlayerDataEntity playerData = new CustomerPlayerDataEntity();
playerData.setWorkspaceKey(Constants.envKeyFp);
CustomerVideoDataEntity videoData = new CustomerVideoDataEntity();
videoData.setVideoId("Video ID");
videoData.setVideoTitle("Video Title");
CustomerViewDataEntity viewData = new CustomerViewDataEntity();
viewData.setViewSessionId(UUID.randomUUID().toString());
CustomDataEntity customData = new CustomDataEntity();
customData.setCustomData1("Data 1");
customData.setCustomData2("Data 2");
// ... up to
customData.setCustomData10("Data 10");
CustomerDataEntity customerData = new CustomerDataEntity(
playerData,
videoData,
viewData
);
customerData.setCustomData(customData);
// 3. FastPix Setup
fastPixBaseMedia3Player = new FastPixBaseMedia3Player(
this,
exoPlayer,
customerData,
new CustomOptions() // optional if default constructor exists
);
// 4. Attach PlayerView
fastPixBaseMedia3Player.setPlayerView(playerView);
}
}
Step 4: Including custom data and metadata
workspaceKey
is the only mandatory field. While all metadata fields are optional, including more information enhances the insights you can gain.
Check out the user-passable metadata documentation to see the metadata supported by FastPix. You can use custom metadata fields like custom_1
to custom_10
for your business logic, giving you the flexibility to pass any required values. Named attributes, such as video_title
and video_id
, can be passed directly as they are.
override fun onCreate(savedInstanceState: Bundle?) {
val customerPlayerDataEntity = CustomerPlayerDataEntity()
customerPlayerDataEntity.workspaceKey = Constants.wsKey
customerPlayerDataEntity.playerName = "Exoplayer"
/* Data about this video Add or change properties here to customize video metadata such as title, language, etc */
val customerVideoDataEntity = CustomerVideoDataEntity ()
customerVideoDataEntity.videoId = “Id”
customerVideoDataEntity.videoTitle = “Title”
customerVideoDataEntity.videoSourceUrl = “UrlSting”
customerVideoDataEntity.videoLanguageCode = "Lang"
customerVideoDataEntity.videoProducer = "Producer"
customerVideoDataEntity.videoContentType = “ItemType”
/* Add values for your Custom Dimensions. Up to 10 strings can be set to track your own data */
val customDataEntity = CustomDataEntity ()
customDataEntity.customData1 = "data1"
customDataEntity.customData2 = "data2"
customDataEntity.customData3 = "data3"
|| || ||
|| || ||
customDataEntity.customData10 = "data10"
/* You need to pass the view session ID into CustomerViewDataEntity*/
val customerViewDataEntity = CustomerViewDataEntity ()
customerViewDataEntity.viewSessionId = UUID.randomUUID().toString()
/* CustomerDataEntity binding with customerPlayerDataEntity, customerVideoDataEntity, customerViewDataEntity */
val customerDataEntity = CustomerDataEntity (
customerPlayerDataEntity,
customerVideoDataEntity,
customerViewDataEntity)
// CustomOptions set customized Domain or else create empty CustomOptions
val customOptions = CustomOptions()
customOptions.beaconDomain = "domain.com"
}
To set up video analytics, create a FastPixBaseMedia3Player object by providing the following parameters: your application's Context (usually the Activity), the ExoPlayer instance, and the CustomerDataEntity
and CustomOptions
objects that you have prepared.
fastPixBaseMedia3Player = FastPixBaseMedia3Player(
this,
exoPlayer,
customerDataEntity,
customOptions
)
If your PlayerView
hasn’t been configured yet, make sure to set it up now. This step is crucial for capturing various viewer context values and accurately tracking the dimensions of the video player.
fastPixBaseMedia3Player.setPlayerView(playerView)
Finally, when destroying the player, make sure to call the FastPixBaseMedia3Player.release()
function to properly release resources.
override fun onDestroy() {
super.onDestroy()
fastPixBaseMedia3Player.release() // Cleanup FastPix tracking
fastPixBaseMedia3Player = null
}
After completing the integration, start playing a video in your player. A few minutes after stopping playback, you’ll see the results in your FastPix Video Data dashboard. Log in to the dashboard, navigate to the workspace associated with your ws_key
, and look for video views.
Step 5: Advanced customization
Enhancing your video player with advanced options can significantly improve user experience and data tracking. Below are key configurations you can implement:
Attribute | Description | Type | Example usage |
---|---|---|---|
automaticErrorTracking | FastPix automatically tracks errors that occur during playback failures. To disable this feature, fastPixBaseMedia3Player.setAutomaticErrorTracking(false) . This allows you to have more control over which errors are considered fatal and helps you manage error reporting. | Boolean | fastPixBaseMedia3Player.setAutomaticErrorTracking(false) |
debug | Set to true to enable debug logs in the console for troubleshooting purposes. | Boolean | debug: true |
automaticErrorTracking: fastPixBaseMedia3Player.setAutomaticErrorTracking = "true or false"
debug: fastPixBaseMedia3Player.enableFPCoreDebug = "true or false"
Step 6: Emit custom events
Configure error tracking preferences
FastPix’s integration with Media3 ExoPlayer automatically tracks fatal errors that occur within the player. However, if a fatal error occurs outside of Media3 ExoPlayer’s context and you want to log it with FastPix, you can do so by calling the fastPixBaseMedia3Player.error
method.
val errorCode = 500 // Custom error code
val errorMessage = "Description of error", // Generalized error message
val errorContext = "Additional context for the error", // Instance-specific information
val errorException = RequestFailureException (errorCode, errorMessage, errorContext)
fastPixBaseMedia3Player.error(errorException)
Note that fastPixBaseMedia3Player.error(errorException)
can be used with or without automatic error tracking. If your application includes retry logic to recover from ExoPlayer errors, you may want to disable automatic error tracking by doing the following:
fastPixBaseMedia3Player.setAutomaticErrorTracking(false)// disable
fastPixBaseMedia3Player.setAutomaticErrorTracking(true)// enable
Changing video streams in player
Effective video view tracking is essential for monitoring multiple videos in the same player within your Android application. You should reset tracking in two key scenarios: when loading a new source (such as in video series or episodic content).
This is done by calling fastPixBaseMedia3Player.videoChange(CustomerVideoDataEntity)
, which will clear all previous video data and reset all metrics for the new video view. Refer to the Metadata section for the list of video details you can provide. While you can include any metadata when changing the video, you should primarily update the values that start with "video".
It's best to update the video information immediately after instructing the player to load the new source.
// Prepare Customer Data
val customerVideoDataEntity = CustomerVideoDataEntity().apply {
videoId = "abc345" // Unique identifier for the new video
videoTitle = "My Other Great Video " // Title of the new video
videoSeries="Weekly Great Videos", // Series name if applicable
}
fastPixBaseMedia3Player.videoChange(CustomerVideoDataEntity)
Example to configure Media3 ExoPlayer
Here are platform-specific examples to help you integrate the FastPix Data SDK with your AndroidX Media3 (ExoPlayer) instance. Use the following Kotlin or Java code into your application:
import io.fastpix.data.entity.*
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.request.CustomOptions
class VideoPlayerActivity : AppCompatActivity() {
private lateinit var exoPlayer: ExoPlayer
private var fastPixBaseMedia3Player: FastPixBaseMedia3Player? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.your_layout) // Uncomment if layout is needed
initializePlayers()
}
private fun initializePlayers() {
// Initialize ExoPlayer
exoPlayer = ExoPlayer.Builder(this).build()
val mediaItem = MediaItem.fromUri("https://your.video.url/here.mp4")
exoPlayer.setMediaItem(mediaItem)
exoPlayer.prepare()
// Prepare Customer Data
val customerPlayerDataEntity = CustomerPlayerDataEntity().apply {
workspaceKey = Constants.envKeyFp
}
val customerVideoDataEntity = CustomerVideoDataEntity().apply {
videoId = "Video ID"
videoTitle = "Video Title"
}
val customerViewDataEntity = CustomerViewDataEntity().apply {
viewSessionId = UUID.randomUUID().toString()
}
val customDataEntity = CustomDataEntity().apply {
customData1 = "Data 1"
customData2 = "Data 2"
// ...
customData10 = "Data 10"
}
val customerDataEntity = CustomerDataEntity(
customerPlayerDataEntity,
customerVideoDataEntity,
customerViewDataEntity
).apply {
setCustomData(customDataEntity)
}
// Initialize FastPixBaseMedia3Player
fastPixBaseMedia3Player = FastPixBaseMedia3Player(
this,
exoPlayer,
customerDataEntity,
CustomOptions() // Optional if default is allowed
)
fastPixBaseMedia3Player?.setPlayerView(playerView) // Replace with actual view binding
}
override fun onDestroy() {
super.onDestroy()
fastPixBaseMedia3Player?.release() // Cleanup FastPix tracking
fastPixBaseMedia3Player = null
}
}
import io.fastpix.data.entity.*;
import io.fastpix.data.exo.FastPixBaseMedia3Player;
import io.fastpix.data.request.CustomOptions;
public class VideoPlayerActivity extends AppCompatActivity {
private ExoPlayer exoPlayer;
private FastPixBaseMedia3Player fastPixBaseMedia3Player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.your_layout); // Uncomment if layout is needed
initializePlayers();
}
private void initializePlayers() {
// Initialize ExoPlayer
exoPlayer = new ExoPlayer.Builder(this).build();
MediaItem mediaItem = MediaItem.fromUri("https://your.video.url/here.mp4");
exoPlayer.setMediaItem(mediaItem);
exoPlayer.prepare();
// Prepare Customer Data
CustomerPlayerDataEntity customerPlayerDataEntity = new CustomerPlayerDataEntity();
customerPlayerDataEntity.setWorkspaceKey(Constants.envKeyFp);
CustomerVideoDataEntity customerVideoDataEntity = new CustomerVideoDataEntity();
customerVideoDataEntity.setVideoId("Video ID");
customerVideoDataEntity.setVideoTitle("Video Title");
CustomerViewDataEntity customerViewDataEntity = new CustomerViewDataEntity();
customerViewDataEntity.setViewSessionId(UUID.randomUUID().toString());
CustomDataEntity customDataEntity = new CustomDataEntity();
customDataEntity.setCustomData1("Data 1");
customDataEntity.setCustomData2("Data 2");
// ...
customDataEntity.setCustomData10("Data 10");
CustomerDataEntity customerDataEntity = new CustomerDataEntity(
customerPlayerDataEntity,
customerVideoDataEntity,
customerViewDataEntity
);
customerDataEntity.setCustomData(customDataEntity);
// Initialize FastPixBaseMedia3Player
fastPixBaseMedia3Player = new FastPixBaseMedia3Player(
this,
exoPlayer,
customerDataEntity,
new CustomOptions() // Optional if default constructor is allowed
);
fastPixBaseMedia3Player.setPlayerView(playerView); // Replace with actual view binding
}
@Override
p
Updated 1 day ago