FastPix player for Flutter
The FastPix Flutter Player SDK makes it easy to add video playback to your Flutter app. Whether you’re streaming live events or on-demand content, it’s built to handle both with smooth performance. It’s designed specifically for FastPix video streams and integrates cleanly into Flutter workflows, ensuring a smooth and dynamic video playback experience.
You can use the GitHub repository for FastPix Flutter player.
Step 1: Set up media in FastPix
Before writing a single line of Flutter code, you’ll need a playback ID. This is how FastPix identifies which video to stream. The SDK doesn’t care whether your video is live or on-demand, private or public - it just needs that ID.
Here’s how to generate it:
- Log into the FastPix Dashboard using your credentials.
- Create a media asset. You can do this using either the “Push” (you upload to FastPix) or “Pull” (FastPix fetches from your source URL) methods.
- If you’re building this into an automated workflow, you can use the FastPix API to create assets programmatically.
- Once the asset is created, go to the “View Media” page.
- From there, locate the Playback ID. This is what you’ll plug into the Flutter player to stream this video.
PLEASE NOTE
Playback IDs are case-sensitive, and each one maps to a single video stream. If your video is protected, you'll also need to generate a valid JWT token with appropriate access claims.
Step 2: Install the Flutter player SDK
Installing the SDK is straightforward. You’ll use Flutter’s pub tool to add the fastpix_video_player
dependency to your app.
You have two options here:
Option A: Add via terminal
flutter pub add fastpix_video_player
Option B: Add the dependency directly
Alternatively, you can add the dependency directly in your pubspec.yaml
dependencies:
fastpix_video_player: 1.0.0
Then run:
flutter pub get
PLEASE NOTE
If you’re behind a proxy, or using a CI/CD runner, confirm that the SDK is being correctly fetched and cached. You can always verify installation by running flutter pub deps.
Step 3: Import the SDK to your project
Now that the SDK is installed, you need to import it into any Dart file where you want to use FastPix player components. Typically, this will be in a page or file where where you’ll implement video playback features - like your main.dart
or any feature module.
At the very top of the file, add the import statement:
// Import FastPix Flutter Player SDK into Dart files
import 'package:fastpix_player/fastpix_video_player.dart';
This import statement ensures that all the classes, methods, and functionalities provided by the FastPix Flutter Player SDK are available for use in your project.
Step 4: Play a video in your app
Once the SDK is imported, you can begin working with its APIs. This includes initializing the player, configuring playback options, and handling video streams.
You can now leverage the Flutter Player SDK to configure a player controller for streaming a FastPix media using just the playback ID that was generated for the video that you uploaded to FastPix.
4.1 Create a data source
This is the core object that tells the player what to play. You’ll provide:
- The
playbackId
- Stream type (live or on-demand)
- Optional: title, description, thumbnail, token, custom domain
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
title: 'Sample HLS Stream',
description: 'A sample HLS stream from FastPix',
thumbnailUrl: 'https://www.example.com/thumbnail.jpg',
);
4.2 Define Player Configuration
This controls how the player behaves - autoplay settings, quality preferences, controls, etc.
final configuration = FastPixPlayerConfiguration();
4.3 Initialize the Controller
This connects your data source and config to the actual player.
controller = FastPixPlayerController();
controller.initialize(dataSource: dataSource, configuration: configuration);
4.4 Render the Player
Finally, use the FastPixPlayer
widget in your layout. You can control width, height, aspect ratio, and loading indicators.
return FastPixPlayer(
controller: controller,
width: 350,
height: 200,
aspectRatio: FastPixAspectRatio.ratio16x9,
);
PLEASE NOTE
Always dispose the controller in dispose() when the widget is removed. Forgetting this can lead to memory leaks, especially on Android.
Detailed usage example
mport 'package:fastpix_player/fastpix_video_player.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fastpix Player Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const FastPixPlayerDemo(),
);
}
}
class FastPixPlayerDemo extends StatefulWidget {
const FastPixPlayerDemo({super.key});
@override
State<FastPixPlayerDemo> createState() => _FastPixPlayerDemoState();
}
class _FastPixPlayerDemoState extends State<FastPixPlayerDemo> {
late FastPixPlayerController controller;
@override
void initState() {
super.initState();
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
title: 'Sample HLS Stream',
description: 'A sample HLS stream from FastPix',
thumbnailUrl: 'https://www.example.com/thumbnail.jpg',
);
final configuration = FastPixPlayerConfiguration();
controller = FastPixPlayerController();
controller.initialize(dataSource: dataSource, configuration: configuration);
}
@override
Widget build(BuildContext context) {
return FastPixPlayer(
controller: controller,
width: 350,
height: 200,
aspectRatio: FastPixAspectRatio.ratio16x9,
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}
Playback modes - explained in detail
FastPix supports 4 major playback modes. Each is a combination of stream type (live vs on-demand) and access (public vs private).
HLS (HTTP Live Streaming)
HLS (HTTP Live Streaming) is a media streaming protocol developed by Apple. It works by breaking video content into small chunks (typically 2–10 seconds each), which are served over standard HTTP/HTTPS protocols. These chunks are listed in a playlist file (.m3u8) that the player reads to play the video.
Fastpix Flutter Player fully supports HLS streaming, including:
-
.m3u8 playlist parsing.
-
Adaptive bitrate switching.
-
Subtitle tracks and alternative renditions.
1. Public on-demand
Anyone with the link can watch, anytime. No login or token required.
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.onDemand
);
final configuration = FastPixPlayerConfiguration();
controller = FastPixPlayerController();
controller.initialize(dataSource: dataSource, configuration: configuration);
2. Private on-demand
Private playback means the video is available anytime but only to authorized users. Access is secured using a valid JWT token, ensuring only permitted viewers can watch the content. Useful for subscriptions or internal tools.
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.onDemand,
token: "jwt-token"
);
3. Public live stream
Video is streamed in real-time and accessible to anyone with the link, without any authentication or token required. Great for open broadcasts.
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.live,
);
4. Private live stream
Real-time stream with token-based access control. Used for gated events or pay-per-view.
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.live,
token: "jwt-token"
);
PLEASE NOTE
The
streamType
must be explicitly set toStreamType.live
orStreamType.onDemand
. Leaving it blank can lead to unpredictable behavior.
Step 5: Using a custom domain
If your FastPix setup uses a custom CDN domain, you can configure it in the data source. This tells the player to construct URLs using your own domain rather than FastPix defaults.
On-demand from custom domain
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.onDemand,
customDomain: "custom-domain",
token: "jwt-token"
);
Live stream from custom domain
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.live,
customDomain: "custom-domain",
token: "jwt-token"
);
PLEASE NOTE
You don’t need to specify a domain if you’re using FastPix-hosted playback. This step is optional unless you’ve customized your delivery configuration.
Step 6: Control video playback resolution
You can lock the video to a target resolution (say, 720p), or provide min/max bounds like 480p to 1080p. You can also control the order the player uses to pick renditions.
For instance, your app runs in emerging markets where users often have poor connectivity. Start at 480p and scale up only if the network supports it. This allows users to have more control over their viewing experience, reducing buffering and ensuring smooth playback.
renditionOrder: asc
means low quality → high quality.renditionOrder: desc
does the opposite - start at the highest available.
// Quality control configuration
final qualityControl = FastPixPlayerQualityControl(
resolution: FastPixResolution.p720,
minResolution: FastPixResolution.p480,
maxResolution: FastPixResolution.p1080,
renditionOrder: FastPixRenditionOrder.desc, // High to low quality
);
// Create HLS data source
final dataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.live,
qualityControl: qualityControl,
token: "jwt-token"
);
PLEASE NOTE
If
renditionOrder
is set toasc
, the player starts with the lowest resolution and scales up based on network. Usedesc
to prefer high-quality playback right away.
Step 7: Switch videos dynamically
Let’s say you want to play a different video after the first one finishes - or reload the player with a fresh JWT token. You don’t need to reinitialize or rebuild the player. Using updateDataSource()
, you can change the playback ID, domain, or token - for example, to load a new video or refresh access credentials.
// Update data source
final newDataSource = FastPixPlayerDataSource.hls(
playbackId: 'new-playback-id',
customDomain: 'new-domain.com',
token: 'new-token',
);
await controller.updateDataSource(newDataSource);
Live streaming best practices
When streaming live video, use an HLS data source with streamType: StreamType.live
. It’s also important to disable caching, this ensures viewers are as close to real-time as possible and aren’t watching buffered segments.
Example: Live with cache disabled
// Create HLS data source
final liveDataSource = FastPixPlayerDataSource.hls(
playbackId: 'your-playback-id-here',
streamType: StreamType.live,
cacheEnabled: false, // Cache should be disabled for live streaming
customDomain: "custom-domain",
);
PLEASE NOTE
Caching is useful for on-demand playback, but for live events, it introduces unnecessary delay. Always set
cacheEnabled: false
.
Error handling
Error handling in FastPix Player ensures a smooth user experience by showing a custom error UI when playback fails. You can define an errorWidgetBuilder
to display meaningful messages and visuals when errors occur.
FastPixPlayer(
controller: controller,
errorWidgetBuilder: (error) {
return Container(
color: Colors.black,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error, color: Colors.red, size: 48),
SizedBox(height: 16),
Text(
'Playback Error',
style: TextStyle(color: Colors.white, fontSize: 18),
),
SizedBox(height: 8),
Text(
error,
style: TextStyle(color: Colors.white70, fontSize: 14),
textAlign: TextAlign.center,
),
],
),
),
);
},
);
Parameter reference
- FastPix player controller – Main controller class for playback management
Function | Description |
---|---|
initialize(dataSource, configuration) | Initialize the player with a data source and configuration |
play() | Start playback |
pause() | Pause playback |
seekTo(position) | Seek to a specific position |
setVolume(volume) | Set volume (0.0 to 1.0) |
updateDataSource(dataSource) | Update the current data source |
dispose() | Clean up resources |
currentState | Get current player state |
isPlaying | Returns true if playing |
isPaused | Returns true if paused |
isFinished | Returns true if playback is finished |
getCurrentPosition() | Get current playback position |
getTotalDuration() | Get total video duration |
- FastPix player data source - Class to configure streaming source
Parameter | Type | Required? | Description |
---|---|---|---|
playbackId | String | ✅ Yes | Unique identifier for your stream |
format | Enum | ✅ Yes | Stream format (e.g. FastPixStreamingFormat.hls ) |
title | String | No | Optional title for the stream |
description | String | No | Optional description |
customDomain | String | No | Custom streaming domain (default: staging.metrix.io ) |
token | String | No | Token for secured playback |
streamType | Boolean | No | true if live stream |
headers | Map<String, String> | No | Custom HTTP headers |
cacheEnabled | Boolean | No | Enable/disable caching |
loop | Boolean | No | Enable/disable looping |
qualityControl | Object | No | Attach a FastPixPlayerQualityControl object |
- FastPix player configuration – Player behavior customization
Property | Description |
---|---|
controlsConfiguration | Configure UI controls |
autoPlayConfiguration | Auto-play behavior |
qualityConfiguration | Quality selection logic |
- FastPix player quality control – Advanced quality control
Property | Description |
---|---|
resolution | Target resolution (auto , p360 , p480 , etc.) |
minResolution | Set minimum resolution |
maxResolution | Set maximum resolution |
renditionOrder | Define rendition order (default_ , asc , desc ) |
- Widgets
Widget | Description |
---|---|
FastPixPlayer | Core video player widget with full playback controls |
FastPixPlayerState | Represents player state (see below) |
- Player states
State | Description |
---|---|
initialized | Player created but not ready |
ready | Ready to play |
playing | Actively playing |
paused | Paused state |
buffering | Waiting for data |
finished | Playback completed |
error | Error encountered |
- Display options
Value | Description |
---|---|
fit | Fit to screen |
ratio16x9 | Standard 16:9 |
ratio4x3 | Classic 4:3 |
ratio1x1 | Square 1:1 |
stretch | Fill entire screen |
- Autoplay settings
Option | Behavior |
---|---|
enabled | Always auto-play |
disabled | No auto-play |
wifiOnly | Auto-play only on WiFi |
- Supported resolutions
Value | Resolution |
---|---|
auto | Automatic |
p360 | 360p |
p480 | 480p |
p720 | 720p |
p1080 | 1080p |
p1440 | 1440p |
p2160 | 2160p (4K) |
Updated about 9 hours ago