all_in_one_video_player 0.0.3
all_in_one_video_player: ^0.0.3 copied to clipboard
A Flutter video player that supports YouTube, Vimeo, and server links with custom controls.
example/lib/main.dart
/// lib/main.dart
///
/// This is the entry point of the Flutter application.
/// It demonstrates how to use the PlayerWidget with different video sources.
import 'package:flutter/material.dart';
// Import the PlayerWidget and PlayerController from your package.
import 'package:all_in_one_video_player/all_in_one_video_player.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized(); // Make sure this is here
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'All-in-One Video Player Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const VideoPlayerDemoPage(),
);
}
}
class VideoPlayerDemoPage extends StatefulWidget {
const VideoPlayerDemoPage({super.key});
@override
State<VideoPlayerDemoPage> createState() => _VideoPlayerDemoPageState();
}
class _VideoPlayerDemoPageState extends State<VideoPlayerDemoPage> {
// Define controllers for different video sources.
final PlayerController _youtubeController = PlayerController(
videoUrl:
'https://youtu.be/aPCl90cpdDo?si=JH1lk1RhXCBZ3vOx', // Example YouTube video (Maroon 5 - Girls Like You)
sourceType: VideoSourceType.youtube,
);
final PlayerController _vimeoController = PlayerController(
videoUrl: 'https://vimeo.com/347119375', // Example Vimeo video
sourceType: VideoSourceType.vimeo,
);
final PlayerController _serverController = PlayerController(
videoUrl:
'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', // Example server video (MP4)
sourceType: VideoSourceType.server,
);
// Variable to hold the currently selected player controller.
late PlayerController _currentController;
@override
void initState() {
super.initState();
// Set the initial video to play (e.g., YouTube).
_currentController = _youtubeController;
}
@override
Widget build(BuildContext context) {
return Scaffold(
// AppBar is always shown in this parent screen
appBar: AppBar(title: const Text('All-in-One Video Player')),
body: Column(
children: [
// The video player takes up flexible space within the column.
Expanded(
child: Center(
child: AspectRatio(
aspectRatio: 16 / 9,
// PlayerWidget now handles its own fullscreen logic internally
child: PlayerWidget(
controller: _currentController,
// No onFullScreenToggle callback needed here anymore
),
),
),
),
// Buttons to switch between different video sources.
// These buttons are always shown in this parent screen.
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
setState(() {
_currentController = _youtubeController;
});
},
child: const Text('Play YouTube'),
),
ElevatedButton(
onPressed: () {
setState(() {
_currentController = _vimeoController;
});
},
child: const Text('Play Vimeo'),
),
ElevatedButton(
onPressed: () {
setState(() {
_currentController = _serverController;
});
},
child: const Text('Play Server'),
),
],
),
),
],
),
);
}
}