FastPix player for Android

The FastPix Android Player SDK is a full-featured, Media3-based playback library for Android apps. Built on top of ExoPlayer, it supports live and on-demand video streaming, playback security, analytics, track switching, and resolution control — giving you everything you need to deliver reliable, branded, and insight-rich video playback inside your Android applications.

You can use the GitHub repository for FastPix iOS player.


Prerequisites

Before you start, make sure you meet the following development and FastPix setup requirements.

Android environment

  • Android Studio: Arctic Fox or later
  • Android SDK: Version 24+
  • Fastpix Player dependency for Player
  • FastPix ExoPlayer SDK (media3-compatible) as a dependency
  • GitHub Personal Access Token (PAT) for private Maven access

FastPix requirements:

  1. Login to FastPix Dashboard
    Go to dashboard.fastpix.io and sign in.
  2. Create Media
    Use the UI or API to create a media asset (via push or pull URL).
  3. Get Playback ID
    Go to View Media, select your uploaded file, and copy the playbackId.
  4. Use the Playback ID
    This will be required to generate the playback URL in your app.


Step 1: Install and configure the SDK

  1. Open your Android Studio project
    Open the project where you want to integrate the SDK.

  1. Add the FastPix Player SDK dependency

Navigate to your app-level build.gradle file (or build.gradle.kts if using Kotlin DSL) and add:

//Add the following line under the dependencies section: 
dependencies  
{ 
  // check with latest version 
  implementation 'io.fastpix.player:android:1.0.0 ' 
} 

  1. Add GitHub Maven Repo

Navigate to your settings.gradle file. You’ll need a GitHub Personal Access Token to access the private Maven package.

//Add the following lines inside repositories section: 
repositories { 
maven { 
url = uri("https://maven.pkg.github.com/FastPix/fastpix-android-player")    
credentials { 

// Your GitHub account username (or) FastPix  
username = "Github_User_Name" 

// Your (PAT) Personal access token Get It from you Github account 
password = "Github_PAT"   
   	      } 
  	} 
} 

  1. Sync your project with Gradle files

Click "Sync Now" in the notification bar to download and integrate the FastPix Player SDK.

Once the above dependency is added, you can use the FastPix Player SDK module into your Android project where you want to use its functionalities.



Step 2: Import the SDK

Required imports

import io.fastpix.player.* 
import androidx.media3.exoplayer.ExoPlayer 
import androidx.media3.ui.PlayerView 

Globally declare

You need to globally declare the Player instance and MediaFastPixPlayer in your Android application. A global declaration ensures that these objects can be accessed throughout the lifecycle of your activity or application where required.

import ... 

class CustomizedPlayerActivity : AppCompatActivity() { 
 	private lateinit var binding: ActivityCustomizedPlayerBinding 
    private val playerView get() = binding.player 
    private var player: MediaFastPixPlayer? = null 
    private var playbackPosition: Long = 0 
    private var playWhenReady = true 
    private lateinit var fastPixListener: Player.Listener 
} 

This class defines global declarations required for integrating the FastPix Player SDK within an Android activity. It includes a binding variable to access the layout views via ActivityCustomizedPlayerBinding, and a playerView property that provides a shortcut to the FastPix player view component. The player variable holds the instance of MediaFastPixPlayer, which manages video playback. The playbackPosition stores the current position of playback to resume from the same point if needed, and playWhenReady is a flag indicating whether the player should start playing automatically once it's ready.

Additionally, fastPixListener is a Player.Listener instance used to listen to player events such as playback state changes, errors, or analytics callbacks, enabling custom handling of player behavior.


import io.fastpix.fastpixplayer.*  
import androidx.media3.exoplayer.ExoPlayer  
import androidx.media3.ui.PlayerView 

class CustomizedPlayerActivity : AppCompatActivity() {  

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

} 
 
override fun onStart() { 
    super.onStart() 
    startPlayback() 
} 
 
private fun startPlayback() { 
    “”” 
beginPlayback(item) 
} 
 
private fun beginPlayback(mediaItem: MediaItem) { 
   ///Create the Player 
     createPlayer(this) 
} 
 
private fun createPlayer(context: Context): MediaFastPixPlayer { 
   ->SetUp YOUR_WORK_SPACE_KEY  
    “”” 
// Setup Media Fastpix Player instance with required metadata mandatory workspace 
   val mediaFastPixPlayer: MediaFastPixPlayer = MediaFastPixPlayer.Builder(context) 

“”" 
              }.build() 
    return mediaFastPixPlayer 
} 
 
 override fun onStop() { 
    destroyPlayer() 
    super.onStop() 
} 
 
override fun onPause() { 
    super.onPause()  
    destroyPlayer() 
} 
 
private fun destroyPlayer() { 
//     Destroy the Player  
} 
} 


Step 3: Playback setup and use cases

A. Public media playback (with Stream Type)

private fun startPlayback() { 
    val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 
        playbackId = "YOUR_PLAYBACK_ID",//PlaybackId is mandatory input 
        streamType = "SET_STREAM_TYPE"//StreamType set by defalt as "on-demand" and set as live-stream play with live video 
    ) 
   } 

Points for playback using playback-id and stream-type configuration:

Stream type notes:

  • on-demand is default (for pre-recorded media)
  • Set streamType to "live-stream" for real-time playback
  • Playback becomes available as soon as the media status is marked as "ready" on the server.

B. Secure playback (token-based)

private fun startPlayback() { 
        val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 

 
            playbackId = "YOUR_PLAYBACK_ID",//PlaybackId is mandatory input 
            playbackToken = "SET_PLAYBACK_TOKEN",//playbackToken 
        ) 
} 

Token benefits:

  • Unique playback ID: Identifies each video asset individually for secure and trackable playback.
  • Signed token authentication: Grants access only if a valid, cryptographically signed token is present in the playback URL.
  • Time-limited access: Tokens can include expiration timestamps to allow playback only within a defined time window.
  • User-specific control: Tokens can be generated per user or session, restricting access based on identity or device.
  • Prevents unauthorized sharing: Signed tokens stop others from reusing the URL, protecting content from piracy and hotlinking.
  • Customizable restrictions: Tokens can include rules like IP restrictions, usage limits, or geo-blocking for enhanced security.

C. Playback resolution control

private fun startPlayback() { 
        val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 
            playbackId = "YOUR_PLAYBACK_ID",//PlaybackId is mandatory input 
            minResolution = "SET_MIN_RESOLUTION",//PlaybackResolution.LD_480 
            maxResolution = "SET_MAX_RESOLUTION",//PlaybackResolution.FHD_1080 
            resolution = "SET_RESOLUTION",//PlaybackResolution.LD_480 
        ) 
} 

Benefits:

  • Min/max resolution: Set quality boundaries to manage bandwidth and device performance.
  • Fixed resolution: Force playback at a specific resolution (e.g., always 720p).
  • Adaptive range: Let the player switch between defined min–max levels (e.g., between 480p and 1080p) based on network.
  • Optimized playback: Achieve smoother streaming by balancing quality and performance.
  • Full control: Tailor video quality to user settings or app-specific requirements.

D. Rendition order (quality preference)

Define which resolutions should be preferred during adaptive playback (e.g., prefer HD over SD when available). You can align playback quality with user-selected settings (like “Data Saver,” “Auto,” or “High Quality”).

The player intelligently switches resolutions based on real-time network and device conditions, while respecting the set priorities. This also helps avoid sudden quality drops or unnecessary resolution changes, maintaining smoother playback.


private fun startPlayback() { 
        val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 
            playbackId = "YOUR_PLAYBACK_ID",//PlaybackId is mandatory input 
            renditionOrder = "SET_RENDITION_ORDER",//RenditionOrder.Descending 
        ) 
} 

Modes:

  • Ascending: 144p → 360p → 720p → 1080p (quick startup)
  • Descending: 1080p → 720p → 360p → 144p (best-quality first)

E. Custom domain support

private fun startPlayback() { 
        val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 
            playbackId = "YOUR_PLAYBACK_ID",//PlaybackId is mandatory input 
            customDomain = "SET_CUSTOM_DOMAIN"//customDomain 
        ) 
} 

Why use custom domain:

  • Stream videos directly from your own domain (e.g., stream.yoursite.com) instead of default CDN URLs.
  • Supports public & private content
  • You can use signed playback tokens for private videos to restrict access to authorized users only.
  • Manage who can view your content with minimal setup using domain and token-based security.
  • Hosting via your custom domain can improve performance and ensure better branding consistency.
  • Seamless transition for white-labeled apps.

Detailed example

The complete example includes listener setup, analytics metadata, URL generation, and player configuration.

import io.fastpix.fastpixplayer.*  
import androidx.media3.exoplayer.ExoPlayer  
import androidx.media3.ui.PlayerView 

class CustomizedPlayerActivity : AppCompatActivity() {  
private lateinit var binding: ActivityCustomizedPlayerBinding  
private val playerView get() = binding.player  
private var player: MediaFastPixPlayer? = null  
private var playbackPosition: Long = 0  
private var playWhenReady = true  
private lateinit var fastPixListener: Player.Listener 

override fun onCreate(savedInstanceState: Bundle?) { 
    super.onCreate(savedInstanceState) 
    binding = ActivityCustomizedPlayerBinding.inflate(layoutInflater) 
    setContentView(binding.root) 
} 
 
override fun onStart() { 
    super.onStart() 
    startPlayback() 
} 
 
private fun startPlayback() { 
    fastPixListener = object : Player.Listener { 
        override fun onPlayerError(error: PlaybackException) { 
            Toast.makeText( 
                this@CustomizedPlayerActivity, 

"Playback error! ${error.localizedMessage}", 
                Toast.LENGTH_LONG 
            ).show() 
        } 
    } 
    FastPixUrlGenerator.setPlayerListener(fastPixListener) 
    val mediaItem = FastPixUrlGenerator.createCustomPlaybackUri( 
        playbackId = "YOUR_PLAYBACK_ID",//playbackId is mandatory input 
        minResolution = "SET_MIN_RESOLUTION",//PlaybackResolution.LD_480 
        maxResolution = "SET_MAX_RESOLUTION",//PlaybackResolution.FHD_1080 
        resolution = "SET_RESOLUTION",//PlaybackResolution.LD_480 
        renditionOrder = "SET_RENDITION_ORDER",//RenditionOrder.Descending 
        playbackToken = "SET_PLAYBACK_TOKEN",//playbackToken 
        customDomain = "SET_CUSTOM_DOMAIN",//customDomain 
        streamType = "SET_STREAM_TYPE"//streamType set as "live-stream or on-demand" 
    )?:return 
    if (player != null ) { 
        player!!.playWhenReady = false 
    } 
    val item = mediaItem.build() 
    if (item != player?.currentMediaItem) { 
        beginPlayback(item) 
    } 
} 
 
private fun beginPlayback(mediaItem: MediaItem) { 
 
    val player = createPlayer(this) 
    player.setMediaItem(mediaItem) 
    player.prepare() 
    player.playWhenReady = playWhenReady 
    player.seekTo(playbackPosition) 
    this.playerView.player = player 
    this.player = player 
} 
 
private fun createPlayer(context: Context): MediaFastPixPlayer { 
    val customerPlayerDataEntity = CustomerPlayerDataEntity() 
    customerPlayerDataEntity.workspaceKey = "YOUR_WORK_SPACE_KEY"// WorkspaceKey get it from fastpix dashboard 
    

val customerViewDataEntity = CustomerViewDataEntity() 
    customerViewDataEntity.viewSessionId = UUID.randomUUID().toString() 
 
    val customerVideoDataEntity = CustomerVideoDataEntity() 
    customerVideoDataEntity.videoId = "videoId" 
    customerVideoDataEntity.videoTitle = "videoTitle" 
 
    val customDataEntity = CustomDataEntity() 
    customDataEntity.customData1 = "item1" 
    customDataEntity.customData2 = "item2" 
     //     	  ||                   || 
     //         	  ||                   ||  
    customDataEntity.customData10 = "item10" 
 
    val customerDataEntity = CustomerDataEntity( 
        customerPlayerDataEntity, 
        customerVideoDataEntity, 
        customerViewDataEntity 
    ) 
    customerDataEntity.setCustomData(customDataEntity) 
 
    val mediaFastPixPlayer: MediaFastPixPlayer = MediaFastPixPlayer.Builder(context) 
        .pushMonitoringData(customerDataEntity) 
        .configureExoPlayer { 
            setHandleAudioBecomingNoisy(true) 
        }.build() 
 
 
    mediaFastPixPlayer.addListener(fastPixListener) 
 
 
    return mediaFastPixPlayer 
} 
 
 override fun onStop() { 
    destroyPlayer() 
    super.onStop() 
} 
 
override fun onPause() { 
    super.onPause() 

destroyPlayer() 
} 
 
private fun destroyPlayer() { 
    if (player != null ) { 
        playbackPosition = player!!.currentPosition 
        playWhenReady = player!!.playWhenReady 
        playerView?.player = null 
        player?.release() 
        player = null 
    } 
} 

} 

Notes:

  • Activity setup: CustomizedPlayerActivity uses view binding (ActivityCustomizedPlayerBinding) to access the player view from the layout.
  • Player instance management: A MediaFastPixPlayer instance is created and released in onStart, onPause, and onStop to manage playback lifecycle and memory.
  • Playback listener: A custom Player.Listener is set up to handle playback errors and other player events.
  • Secure playback URL generation: FastPixUrlGenerator.createCustomPlaybackUri() generates the video URL using required inputs like playbackId, optional playback token, resolution settings, custom domain, and stream type (live or on-demand).
  • Resolution & stream type config: Supports setting minimum, maximum, or fixed resolution, and choosing between live or on-demand streams.
  • Video Data integration: Player is initialized with CustomerDataEntity that includes workspace key, session ID, video info, and up to 10 custom data fields for tracking and analytics.
  • Player configuration: Uses configureExoPlayer to set player behaviors like handling audio becoming noisy (e.g., headphones unplugged).
  • Playback handling: If a new media item is loaded, beginPlayback() initializes the player with the media item and restores previous playback state.
  • Resource cleanup: destroyPlayer() is called during pause/stop to release resources, saving current playback position and state.

By following the setup steps, you've successfully integrated the FastPix Android Player SDK into your project. Whether you're building a secure on-demand streaming app or a live broadcast platform, you're now ready to deliver high-quality video playback with ease.