> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fastpix.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/docs/_mcp/server.

# Set up the player

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

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

## Required imports

```kotlin
import io.fastpix.media3.PlayerView
import io.fastpix.media3.PlaybackListener
import io.fastpix.media3.core.FastPixPlayer
import io.fastpix.media3.core.PlaybackResolution
import io.fastpix.media3.core.RenditionOrder
import io.fastpix.media3.core.StreamType
import androidx.media3.common.MediaItem
import 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:

```kotlin
class CustomizedPlayerActivity : AppCompatActivity() {
    private lateinit var binding: ActivityCustomizedPlayerBinding
    private val playerView get() = binding.playerView
    private var player: FastPixPlayer? = null
    private lateinit var playbackListener: PlaybackListener
}
```

## Initialize the player

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

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityCustomizedPlayerBinding.inflate(layoutInflater)
    setContentView(binding.root)

    player = FastPixPlayer.Builder(this)
        .setAutoplay(true)
        .setLoop(false)
        .build()
    playerView.player = player
}
```

## 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:

```kotlin
override fun onDestroy() {
    super.onDestroy()
    player?.removePlaybackListener(playbackListener)
    if (isFinishing) {
        playerView.release()
    }
}
```

## What's next

* [Play uploaded videos](/docs/android-player/play-uploaded-videos) to start streaming content.
* [Listen to playback events](/docs/android-player/listen-to-playback-events) to observe player state changes.