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.1.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.domain.model.CustomDataDetails
import io.fastpix.data.domain.model.VideoDataDetails
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.domain.model.PlayerDataDetailsStep 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 fastPixDataSDK: 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.domain.model.CustomDataDetails
import io.fastpix.data.domain.model.VideoDataDetails
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.domain.model.PlayerDataDetails
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)
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()
val videoDataDetails = VideoDataDetails("video-id", "video-title").apply {
videoSeries = "video-series"
videoProducer = "video-producer"
videoContentType = "video-content-type"
videoVariant = "video-variant"
videoLanguage = "video-language"
videoDuration = "video-duration"
//...etc
}
val customDataDetails = CustomDataDetails().apply {
customField1 = "custom-one"
customField2 = "custom-two"
//...etc
}
// By Default player sets these things, You don't have to worry about it unless you're not using
// some wrapper around media3
val playerDataDetails = PlayerDataDetails(
playerName = "media3",
playerVersion = "latest-version"
)
fastPixDataSDK = FastPixBaseMedia3Player(
this, // context
playerView = binding.playerView, // media3 playerView from XML
exoPlayer = exoPlayer, // media3 player
beaconUrl = "beacon-url",
workSpaceId = "workspace-id",
playerDataDetails = playerDataDetails,
videoDataDetails = videoDataDetails,
customDataDetails = customDataDetails
)
}
}import io.fastpix.data.domain.model.CustomDataDetails
import io.fastpix.data.domain.model.VideoDataDetails
import io.fastpix.data.exo.FastPixBaseMedia3Player
import io.fastpix.data.domain.model.PlayerDataDetails
public class VideoPlayerActivity extends AppCompatActivity {
private ExoPlayer exoPlayer;
private FastPixBaseMedia3Player fastPixDataSDK;
// You’ll need to define this or use ViewBinding
private PlayerView playerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
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. Video Details Data (Optional)
VideoDataDetails videoDataDetails = new VideoDataDetails("video-id", "video-title");
videoDataDetails.setVideoSeries("video-series");
videoDataDetails.setVideoProducer("video-producer");
videoDataDetails.setVideoContentType("video-content-type");
videoDataDetails.setVideoVariant("video-variant");
videoDataDetails.setVideoLanguage("video-language");
videoDataDetails.setVideoDuration("video-duration");
// ... etc
// 3. Custom Data Details (Optional)
CustomDataDetails customDataDetails = new CustomDataDetails();
customDataDetails.setCustomField1("Custom 1");
customDataDetails.setCustomField2("Custom 2");
// ... etc
// By default player sets these things, you don't have to worry about it
// unless you're using some wrapper around Media3
// 4. Player Data Details (Optional)
PlayerDataDetails playerDataDetails = new PlayerDataDetails(
"media3", // playerName
"latest-version" // playerVersion
);
fastPixDataSDK = new FastPixBaseMedia3Player(
this, // context
binding.getPlayerView(), // media3 PlayerView from XML
exoPlayer, // media3 player instance
"xyz.com", // Domain name (Optional)
"workspace-id", // workSpaceId
playerDataDetails, // player data (Optional)
videoDataDetails, // video data (Optional)
customDataDetails // custom data (Optional)
);
}
}Step 4: Including custom data and metadata
workSpaceIdis a mandatory parameter that tells the SDK on which workspace the data will collect.playerViewis another mandatory parameter.exoPlayeris also a mandatory parameter that SDK uses to anylyze the playback.
Check out the user-passable metadata documentation to see the metadata supported by FastPix. You can use custom metadata fields like customField1 to customField9 for your business logic, giving you the flexibility to pass any required values. Named attributes, such as videoTitle and videoId, can be passed directly as they are.
override fun onCreate(savedInstanceState: Bundle?) {
// 1. Video Data Details (Optional)
val videoDataDetails = VideoDataDetails("video-id", "video-title").apply {
videoSeries = "video-series"
videoProducer = "video-producer"
videoContentType = "video-content-type"
videoVariant = "video-variant"
videoLanguage = "video-language"
videoDuration = "video-duration"
//...etc
}
// 2. Custom Data Details (Optional)
val customDataDetails = CustomDataDetails().apply {
customField1 = "Custom 1"
customField2 = "Custom 2"
//...etc
}
// By Default player sets these things, You don't have to worry about it unless you're not using
// some wrapper around media3
// 3. Player Data Details (Optional)
val playerDataDetails = PlayerDataDetails(
playerName = "media3",
playerVersion = "latest-version"
)
} To set up video analytics, create a FastPixBaseMedia3Player object by providing the following parameters: your application's Context (usually the Activity), the player-view ,exo-playerinstance, workspace-id, player-data-details, viwer-id, video-data-details and custom-data-details objects that you have prepared.
fastPixDataSDK = FastPixBaseMedia3Player(
this, // context
playerView = binding.playerView, // media3 playerView from XML
exoPlayer = exoPlayer, // media3 player
workSpaceId = "workspace-id",
playerDataDetails = playerDataDetails, // Optional
videoDataDetails = videoDataDetails, // Optional
customDataDetails = customDataDetails // Optional
)Finally, when destroying the player, make sure to call the FastPixBaseMedia3Player.release() function to properly release resources.
override fun onDestroy() {
super.onDestroy()
fastPixDataSDK.release() // Cleanup FastPix tracking
fastPixDataSDK = 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.
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.domain.model.CustomDataDetails
import io.fastpix.data.domain.model.PlayerDataDetails
import io.fastpix.data.domain.model.VideoDataDetails
import io.fastpix.data.exo.FastPixBaseMedia3Player
class VideoPlayerActivity : AppCompatActivity() {
private lateinit var exoPlayer: ExoPlayer
private var fastPixDataSDK: FastPixBaseMedia3Player? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_video_player)
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()
// Optional
val videoDataDetails = VideoDataDetails("video-id", "video-title").apply {
videoSeries = "video-series"
videoProducer = "video-producer"
videoContentType = "video-content-type"
videoVariant = "video-variant"
videoLanguage = "video-language"
videoDuration = "video-duration"
//...etc
}
// Optional
val customDataDetails = CustomDataDetails().apply {
customField1 = "Custom 1"
customField2 = "Custom 2"
//...etc
}
// By Default player sets these things, You don't have to worry about it unless you're not using
// some wrapper around media3
// Optional
val playerDataDetails = PlayerDataDetails(
playerName = "media3",
playerVersion = "latest-version"
)
fastPixDataSDK = FastPixBaseMedia3Player(
this, // context
playerView = binding.playerView, // media3 playerView from XML
exoPlayer = exoPlayer, // media3 player
beaconUrl = "beacon-url",
workSpaceId = "workspace-id",
playerDataDetails = playerDataDetails,
videoDataDetails = videoDataDetails,
customDataDetails = customDataDetails
)
}
override fun onDestroy() {
super.onDestroy()
fastPixDataSDK?.release() // Cleanup FastPix tracking
fastPixDataSDK = null
}
}
import io.fastpix.data.domain.model.CustomDataDetails
import io.fastpix.data.domain.model.PlayerDataDetails
import io.fastpix.data.domain.model.VideoDataDetails
import io.fastpix.data.exo.FastPixBaseMedia3Player
public class VideoPlayerActivity extends AppCompatActivity {
private ExoPlayer exoPlayer;
private FastPixBaseMedia3Player fastPixDataSDK;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
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();
// 1. Video Data Details (Optional)
VideoDataDetails videoDataDetails = new VideoDataDetails("video-id", "video-title");
videoDataDetails.setVideoSeries("video-series");
videoDataDetails.setVideoProducer("video-producer");
videoDataDetails.setVideoContentType("video-content-type");
videoDataDetails.setVideoVariant("video-variant");
videoDataDetails.setVideoLanguage("video-language");
videoDataDetails.setVideoDuration("video-duration");
// ... etc
// 2. Custom Data Details (Optional)
CustomDataDetails customDataDetails = new CustomDataDetails();
customDataDetails.setCustomField1("Custom 1");
customDataDetails.setCustomField2("Custom 2");
// ... etc
// By default player sets these things, you don't have to worry about it
// unless you're using some wrapper around Media3
// 3. Player Data Details (Optional)
PlayerDataDetails playerDataDetails = new PlayerDataDetails(
"media3", // playerName
"latest-version" // playerVersion
);
FastPixBaseMedia3Player fastPixDataSDK = new FastPixBaseMedia3Player(
this, // context
binding.getPlayerView(), // media3 PlayerView from XML
exoPlayer, // media3 player instance
"xyz.com", // domain (Optional)
"workspace-id", // workSpaceId
playerDataDetails, // player data (Optional)
videoDataDetails, // video data (Optional)
customDataDetails // custom data (Optional)
);
}
@override
void onDestroy() {
super.onDestroy()
if(fastPixDataSDK!=null){
fastPixDataSDK.release() // Cleanup FastPix tracking
}
fastPixDataSDK = null
}Changelog
All notable changes to the Android Media3 Video Data SDK is documented below.
Current version
v1.1.0
Changed
- Major Code Optimization and Refactoring:
- Comprehensive code refactoring for improved maintainability and performance.
- Optimized internal components and dependencies for better efficiency.
- Enhanced code structure and organization across the SDK.
- Improved overall stability and reduced technical debt.
Added
- Code Update:
- Variable types are improved.
- Bugs are fixed.
- Events work better now.
v1.0.1
Added
- Code Update:
- Variable types are improved.
- Bugs are fixed.
- Events work better now.
Previous version
v1.0.0
Added
- Integration with Media3 ExoPlayer:
- Enabled video performance tracking using FastPix Data SDK, supporting Media3 ExoPlayer streams with user engagement metrics, playback quality monitoring, and real-time diagnostics.
- Provides robust error management and reporting capabilities for seamless Media3 ExoPlayer video performance tracking.
- Allows customizable behavior, including options to disable data collection, respect Do Not Track settings, and configure advanced error tracking with automatic error handling.
- Includes support for custom metadata, enabling users to pass optional fields such as video_id, video_title, video_duration, and more.
- Introduced event tracking for onPlayerStateChanged and onTracksChanged to handle seamless metadata updates during playback transitions.
Updated 3 days ago