Complete integration example

A full example showing how to set up the FastPix Flutter Player with video playback, configuration, and resource cleanup.

Full app example

This example demonstrates a complete Flutter app with player initialization, playback, and cleanup:

1import 'package:fastpix_player/fastpix_video_player.dart';
2import 'package:flutter/material.dart';
3
4import { PageSchema } from "../../../../components/PageSchema";
5
6<PageSchema
7 headline={"Flutter Player: Complete integration example | FastPix"}
8 description={"See a complete integration with the FastPix Flutter player SDK. Step-by-step guide with runnable Dart code and adaptive HLS playback for your app right now."}
9 url={"https://fastpix.com/docs/flutter-player/complete-integration-example"}
10 breadcrumb={["Video Player", "Flutter player", "Examples", "Complete integration example"]}
11/>
12
13void main() {
14 runApp(const MyApp());
15}
16
17class MyApp extends StatelessWidget {
18 const MyApp({super.key});
19
20 @override
21 Widget build(BuildContext context) {
22 return MaterialApp(
23 title: 'Fastpix Player Demo',
24 theme: ThemeData(
25 colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
26 ),
27 home: const FastPixPlayerDemo(),
28 );
29 }
30}
31
32class FastPixPlayerDemo extends StatefulWidget {
33 const FastPixPlayerDemo({super.key});
34
35 @override
36 State<FastPixPlayerDemo> createState() => _FastPixPlayerDemoState();
37}
38
39class _FastPixPlayerDemoState extends State<FastPixPlayerDemo> {
40 late FastPixPlayerController controller;
41
42 @override
43 void initState() {
44 super.initState();
45
46 // Create HLS data source
47 final dataSource = FastPixPlayerDataSource.hls(
48 playbackId: 'your-playback-id-here',
49 title: 'Sample HLS Stream',
50 description: 'A sample HLS stream from FastPix',
51 thumbnailUrl: 'https://www.example.com/thumbnail.jpg',
52 );
53
54 final configuration = FastPixPlayerConfiguration();
55 controller = FastPixPlayerController();
56 controller.initialize(dataSource: dataSource, configuration: configuration);
57 }
58
59 @override
60 Widget build(BuildContext context) {
61 return FastPixPlayer(
62 controller: controller,
63 width: 350,
64 height: 200,
65 aspectRatio: FastPixAspectRatio.ratio16x9,
66 );
67 }
68
69 @override
70 void dispose() {
71 controller.dispose();
72 super.dispose();
73 }
74}

Key points

  • The FastPixPlayerController is created in initState and disposed in dispose to prevent memory leaks.
  • FastPixPlayerDataSource.hls() constructs the data source using a playback ID. Optional fields include title, description, thumbnailUrl, token, customDomain, and qualityControl.
  • FastPixPlayerConfiguration() uses default settings. Customize it with controlsConfiguration, autoPlayConfiguration, and qualityConfiguration.
  • The FastPixPlayer widget renders the video. Set width, height, and aspectRatio to control the layout.

Replace 'your-playback-id-here' with your actual FastPix playback ID.