Skip to navigation

Complete integration example

A full example showing how to set up the FastPix Android Player with playback, seek preview, resolution control, and analytics.

Full Activity setup

This example demonstrates a complete Activity with player initialization, listener registration, seek preview, analytics, resolution control, custom domain, and resource cleanup:

import io.fastpix.media3.PlayerView
import io.fastpix.media3.PlaybackListener
import io.fastpix.media3.analytics.AnalyticsConfig
import io.fastpix.media3.core.FastPixPlayer
import io.fastpix.media3.core.PlaybackResolution
import io.fastpix.media3.core.RenditionOrder
import io.fastpix.media3.seekpreview.models.PreviewFallbackMode
import io.fastpix.media3.seekpreview.models.SeekPreviewConfig
import io.fastpix.data.domain.model.VideoDataDetails
import androidx.media3.common.PlaybackException
class CustomizedPlayerActivity : AppCompatActivity() {
private lateinit var binding: ActivityCustomizedPlayerBinding
private val playerView get() = binding.playerView
private var player: FastPixPlayer? = null
private lateinit var playbackListener: PlaybackListener
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCustomizedPlayerBinding.inflate(layoutInflater)
setContentView(binding.root)
// Configure seek preview
val seekPreviewConfig = SeekPreviewConfig.Builder()
.setEnabled(true)
.setFallbackMode(PreviewFallbackMode.TIMESTAMP)
.setEnablePreload(true)
.setPreloadRadius(1)
.setCacheEnabled(true)
.build()
// Configure analytics
val analyticsConfig = AnalyticsConfig.Builder(playerView, "YOUR_WORKSPACE_ID")
.setVideoDataDetails(VideoDataDetails(videoId = "videoId", videoTitle = "videoTitle"))
.setEnabled(true)
.build()
// Build the player
player = FastPixPlayer.Builder(this)
.setAutoplay(true)
.setLoop(false)
.setSeekPreviewConfig(seekPreviewConfig)
.setAnalyticsConfig(analyticsConfig)
.build()
playerView.player = player
}
override fun onStart() {
super.onStart()
startPlayback()
}
private fun startPlayback() {
// Set up the playback listener
playbackListener = object : PlaybackListener {
override fun onPlay() {}
override fun onPause() {}
override fun onPlaybackStateChanged(isPlaying: Boolean) {}
override fun onError(error: PlaybackException) {}
}
player?.addPlaybackListener(playbackListener)
// Configure and start playback
val ok = player?.setFastPixMediaItem {
playbackId = "YOUR_PLAYBACK_ID"
minResolution = PlaybackResolution.LD_480
maxResolution = PlaybackResolution.FHD_1080
renditionOrder = RenditionOrder.Descending
playbackToken = "SET_PLAYBACK_TOKEN"
customDomain = "SET_CUSTOM_DOMAIN"
} ?: false
if (!ok) return
}
override fun onStop() { super.onStop() }
override fun onPause() { super.onPause() }
override fun onDestroy() {
super.onDestroy()
player?.removePlaybackListener(playbackListener)
if (isFinishing) {
playerView.release()
}
}
}

Key points

  • Uses view binding (ActivityCustomizedPlayerBinding) to access PlayerView from the layout.
  • A FastPixPlayer instance is created once and attached to PlayerView.
  • A PlaybackListener observes playback state and errors.
  • setFastPixMediaItem { ... } generates the playback URL using playbackId plus optional parameters.
  • Seek preview and analytics are configured through the builder.
  • Call playerView.release() in onDestroy() when the Activity is finishing to release resources.

Replace the placeholder values with your actual workspace ID, playback ID, token, and custom domain.