Set up the player
Learn how to import the FastPix Android Player SDK and initialize the player in your Activity.
Required imports
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:
Initialize the player
Create a FastPixPlayer instance using the builder pattern and attach it to your PlayerView:
PlayerView XML tips
When using io.fastpix.media3.PlayerView in your XML layout, keep these properties in mind:
- Configuration-change survival:
PlayerView.retainPlayerOnConfigChangeistrueby default. Assign anandroid:idin XML so the view can retain the player instance across rotation. - Tap gesture: Set
playerView.isTapGestureEnabled = trueto enable single-tap toggle play/pause usingtogglePlayPause(). - Release: Call
playerView.release()inonDestroywhen 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:
What’s next
- Play uploaded videos to start streaming content.
- Listen to playback events to observe player state changes.