Integrate video data with Android player
Integrate video data with Android player
FastPix Android Player supports data integration for tracking video playback, user interaction, and environment details using the AnalyticsConfig builder with metadata fields passed via VideoDataDetails, PlayerDataDetails, and CustomDataDetails.
1. How it works
The recipe imports the FastPix analytics and data model classes. AnalyticsConfig manages the tracking session, while VideoDataDetails, PlayerDataDetails, and CustomDataDetails are typed data classes for passing metadata to the analytics dashboard.
2. Building the analytics configuration
3. Describing the video
4. Enabling analytics
5. Identifying the player
6. Passing custom fields
7. Creating the player with analytics
8. Binding player to view and setting media
1import io.fastpix.media3.analytics.AnalyticsConfig
2import io.fastpix.data.domain.model.VideoDataDetails
3import io.fastpix.data.domain.model.PlayerDataDetails
4import io.fastpix.data.domain.model.CustomDataDetails
5import io.fastpix.media3.core.FastPixPlayer
6import io.fastpix.media3.PlayerView
7
8// Build the analytics configuration
9val analyticsConfig = AnalyticsConfig.Builder(
10 playerView, // Your PlayerView instance
11 "YOUR_WORKSPACE_KEY" // Unique key to identify your workspace (replace with your actual workspace key)
12)
13 .setVideoDataDetails(
14 VideoDataDetails(
15 videoId = "f01a98s76t90p88i67x", // A unique identifier for the video (replace with your actual video ID)
16 videoTitle = "Play Video" // Title of the video being played (replace with the actual title)
17 )
18 )
19 .setEnabled(true) // Enable or disable analytics tracking
20 .setPlayerDataDetails(
21 PlayerDataDetails(
22 playerName = "FastPix Android Player", // Name of the player integration
23 playerVersion = "1.0.7" // Version of the player SDK in use
24 )
25 )
26 .setCustomDataDetails(
27 CustomDataDetails(
28 customField1 = "series", // Use custom fields for any additional business logic (e.g., content type)
29 customField2 = "on-demand", // e.g., stream type
30 customField3 = "user12345" // e.g., viewer ID
31 // customField4 through customField10 are also available
32 )
33 )
34 .build()
35
36// Create FastPixPlayer with analytics enabled
37val fastPixPlayer = FastPixPlayer.Builder(this)
38 .setAutoplay(true)
39 .setAnalyticsConfig(analyticsConfig)
40 .build()
41
42// Pass the configured player to your PlayerView
43playerView.player = fastPixPlayer
44
45// Set the media item for playback
46fastPixPlayer.setFastPixMediaItem {
47 playbackId = "YOUR_PLAYBACK_ID"
48}