For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
StatusSupportDiscussionsLog inSign Up
Docs HomeAPI ReferenceVideo on DemandAI FeaturesLive StreamingVideo PlayerVideo DataCloud PlayoutRecipes
Docs HomeAPI ReferenceVideo on DemandAI FeaturesLive StreamingVideo PlayerVideo DataCloud PlayoutRecipes
  • Player SDKs
    • Introduction
  • Web player
    • Install the FastPix web player
    • Play uploaded videos
    • Handle playback errors
  • Android player
    • Install FastPix Android player
    • Set up the player
    • Play uploaded videos
    • Handle playback errors
  • iOS player
    • Install FastPix iOS player
    • Play uploaded videos
    • Handle playback errors
  • Flutter player
    • Install FastPix Flutter player
    • Play uploaded videos
    • Handle playback errors
LogoLogo
StatusSupportDiscussionsLog inSign Up
On this page
  • Required imports
  • Declare player objects
  • Initialize the player
  • PlayerView XML tips
  • Clean up resources
  • What’s next
Android player

Set up the player

Was this page helpful?
Previous

Play uploaded videos

Next
Built with

Learn how to import the FastPix Android Player SDK and initialize the player in your Activity.

Required imports

1import io.fastpix.media3.PlayerView
2import io.fastpix.media3.PlaybackListener
3import io.fastpix.media3.core.FastPixPlayer
4import io.fastpix.media3.core.PlaybackResolution
5import io.fastpix.media3.core.RenditionOrder
6import io.fastpix.media3.core.StreamType
7import androidx.media3.common.MediaItem
8import androidx.media3.common.PlaybackException

Declare player objects

You can either use PlayerView on its own (it auto-creates a FastPixPlayer with default settings), or create a configured FastPixPlayer and attach it to PlayerView.

Declare the player objects globally in your Activity or Fragment so they’re accessible throughout the lifecycle:

1class CustomizedPlayerActivity : AppCompatActivity() {
2 private lateinit var binding: ActivityCustomizedPlayerBinding
3 private val playerView get() = binding.playerView
4 private var player: FastPixPlayer? = null
5 private lateinit var playbackListener: PlaybackListener
6}

Initialize the player

Create a FastPixPlayer instance using the builder pattern and attach it to your PlayerView:

1override fun onCreate(savedInstanceState: Bundle?) {
2 super.onCreate(savedInstanceState)
3 binding = ActivityCustomizedPlayerBinding.inflate(layoutInflater)
4 setContentView(binding.root)
5
6 player = FastPixPlayer.Builder(this)
7 .setAutoplay(true)
8 .setLoop(false)
9 .build()
10 playerView.player = player
11}

PlayerView XML tips

When using io.fastpix.media3.PlayerView in your XML layout, keep these properties in mind:

  • Configuration-change survival: PlayerView.retainPlayerOnConfigChange is true by default. Assign an android:id in XML so the view can retain the player instance across rotation.
  • Tap gesture: Set playerView.isTapGestureEnabled = true to enable single-tap toggle play/pause using togglePlayPause().
  • Release: Call playerView.release() in onDestroy when the Activity is finishing (isFinishing == true) to force a release even if retention is enabled.

Clean up resources

Remove the playback listener and release the player when the Activity is destroyed:

1override fun onDestroy() {
2 super.onDestroy()
3 player?.removePlaybackListener(playbackListener)
4 if (isFinishing) {
5 playerView.release()
6 }
7}

What’s next

  • Play uploaded videos to start streaming content.
  • Listen to playback events to observe player state changes.