adaptive_video_player 1.0.0
adaptive_video_player: ^1.0.0 copied to clipboard
A Flutter video player package that seamlessly handles both YouTube videos and direct video URLs with adaptive player selection. Supports Android, iOS, Windows, and Web.
๐ฅ Videos Player #
A comprehensive Flutter video player package that seamlessly handles both YouTube videos and direct video URLs with adaptive player selection. Works on ALL Platforms: Android, iOS, macOS, Windows, Linux, and Web.
โจ Features #
๐ฌ Adaptive Video Player #
- Smart Detection โ Automatically detects YouTube vs direct video URLs
- Unified API โ Single
AdaptiveVideoPlayerwidget for all video types - Cross-Platform โ Runs beautifully on Android, iOS, macOS, Windows, Linux, and Web!
๐บ YouTube Player #
- Full YouTube video support with native-like experience
- Custom controls on mobile (seek, settings, fullscreen)
- YouTube native controls on Desktop & Web
- Auto-play, loop, captions, mute, force HD
- Force Desktop Mode on mobile (
forceDesktopMode: trueto use WebViews on Android/iOS) - Settings panel with runtime toggles
- Fullscreen mode with state preservation
๐๏ธ Normal Video Player #
- Supports MP4, MOV, AVI, MKV, WebM, M4V, 3GP, and more
- Network streaming, local file, and in-memory bytes playback
- Powered by Chewie with advanced controls
- Error handling with customizable messages
๐ฅ๏ธ Platform-Specific YouTube Behavior #
| Platform | Engine | Controls |
|---|---|---|
| Android / iOS | youtube_player_flutter |
Custom Flutter controls (seek, settings, fullscreen). Can be forced to Desktop Mode. |
| macOS / Windows / Linux | InAppWebView + localhost server |
YouTube native controls |
| Web | HTML iframe (dart:html) |
YouTube native controls |
Why localhost on Desktop (Windows, macOS, Linux)? YouTube blocks iframe embedding from local files like
data:andfile://(Error 153). Serving viahttp://localhostprovides a trusted origin that YouTube allows.
๐ฆ Installation #
Add to your pubspec.yaml:
dependencies:
adaptive_video_player: ^1.0.0
๐ Platform Permissions & Setup #
To ensure network videos and YouTube play correctly across devices, please configure the required platform permissions:
๐ค Android #
Ensure you have the INTERNET permission in your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
(Optional) For playing http:// (unencrypted) video URLs, also add usesCleartextTraffic to your <application> tag:
<application
...
android:usesCleartextTraffic="true">
๐ iOS #
To allow the YouTube player (which uses Platform Views) to render without being stuck on a loading screen, add the following to your ios/Runner/Info.plist:
<key>io.flutter.embedded_views_preview</key>
<true/>
(Optional) For loading http:// (unencrypted) video URLs safely, also add:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
๐ macOS #
For network video playback and YouTube webview support on macOS, you must grant the application permission to act as a network client.
Open macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements and add the following:
<key>com.apple.security.network.client</key>
<true/>
๐ช Windows #
YouTube playback on Windows requires NuGet for the flutter_inappwebview build:
winget install Microsoft.NuGet
For normal video playback (MP4s, etc.) on Windows, register the video player plugin in main():
import 'package:flutter/foundation.dart';
import 'package:video_player_win/video_player_win_plugin.dart';
void main() {
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
WindowsVideoPlayer.registerWith();
}
runApp(const MyApp());
}
๐ง Linux #
Linux requires WebKit for the flutter_inappwebview playback. Ensure your system has the necessary GTK/WebKit packages installed (e.g., libwebkit2gtk-4.1-dev on Ubuntu/Debian).
๐ Web #
No specific permission files are needed. However, ensure that any external direct videos (MP4, MKV) you stream are hosted on servers with CORS (Cross-Origin Resource Sharing) enabled. YouTube videos are handled automatically via iframe.
๐ Quick Start #
import 'package:adaptive_video_player/adaptive_video_player.dart';
// YouTube video โ detected automatically
AdaptiveVideoPlayer(
config: VideoConfig(
videoUrl: 'https://www.youtube.com/watch?v=vM2dC8OCZoY',
),
)
// Direct video โ detected automatically
AdaptiveVideoPlayer(
config: VideoConfig(
videoUrl: 'https://example.com/video.mp4',
),
)
๐ Usage Examples #
YouTube with Custom Config #
AdaptiveVideoPlayer(
config: VideoConfig(
videoUrl: 'https://www.youtube.com/watch?v=vM2dC8OCZoY',
playerConfig: YouTubePlayerConfig(
playback: PlayerPlaybackConfig(
autoPlay: true,
loop: false,
forceHD: true,
enableCaption: true,
forceDesktopMode: true, // Uses WebViews on Android/iOS instead of native player
),
style: PlayerStyleConfig(
iconColor: Colors.white,
progressBarPlayedColor: Colors.red,
progressBarHandleColor: Colors.redAccent,
backgroundColor: Colors.black,
),
visibility: PlayerVisibilityConfig(
showSettingsButton: true,
showFullscreenButton: true,
),
),
),
)
Local Video File #
AdaptiveVideoPlayer(
config: VideoConfig(
videoUrl: '/path/to/local/video.mp4',
isFile: true,
),
)
Video from Memory #
AdaptiveVideoPlayer(
config: VideoConfig(
videoUrl: '',
videoBytes: myUint8ListBytes,
),
)
๐๏ธ Configuration Reference #
YouTubePlayerConfig #
PlayerPlaybackConfig
| Property | Type | Default | Description |
|---|---|---|---|
autoPlay |
bool |
false |
Auto-start playback |
loop |
bool |
false |
Loop video |
mute |
bool |
false |
Start muted |
forceHD |
bool |
false |
Force HD quality |
enableCaption |
bool |
false |
Enable captions |
PlayerStyleConfig
| Property | Type | Default | Description |
|---|---|---|---|
progressBarPlayedColor |
Color |
Colors.red |
Progress bar color |
progressBarHandleColor |
Color |
Colors.redAccent |
Handle color |
iconColor |
Color |
Colors.white |
Control icons color |
textColor |
Color |
Colors.white |
Text color |
backgroundColor |
Color |
#1D1D1D |
Player background |
loadingIndicatorColor |
Color |
Colors.red |
Loading spinner color |
errorIconColor |
Color |
Colors.red |
Error icon color |
settingsBackgroundColor |
Color |
#1D1D1D |
Settings sheet background |
PlayerTextConfig
| Property | Type | Default |
|---|---|---|
invalidYoutubeUrlText |
String |
"Invalid YouTube URL" |
videoLoadFailedText |
String |
"Failed to load video" |
playerSettingsText |
String |
"Player Settings" |
autoPlayText |
String |
"Auto Play" |
loopVideoText |
String |
"Loop Video" |
forceHdQualityText |
String |
"Force HD Quality" |
enableCaptionsText |
String |
"Enable Captions" |
muteAudioText |
String |
"Mute Audio" |
PlayerVisibilityConfig
| Property | Type | Default |
|---|---|---|
showControls |
bool |
true |
showFullscreenButton |
bool |
true |
showSettingsButton |
bool |
true |
showAutoPlaySetting |
bool |
true |
showLoopSetting |
bool |
true |
showForceHDSetting |
bool |
true |
showCaptionsSetting |
bool |
true |
showMuteSetting |
bool |
true |
๐๏ธ Architecture #
lib/
โโโ adaptive_video_player.dart # Package exports
โโโ adaptive_video_player.dart # Smart YouTube/direct video detection
โโโ normal_video_player/
โ โโโ normal_video_player.dart # Chewie-based video player
โ โโโ model/
โ โโโ video_config.dart # Video configuration model
โโโ youtube_player/
โโโ youtube_video_player.dart # Main YouTube player (platform-aware)
โโโ cubit/
โ โโโ youtube_player_cubit.dart # BLoC state management
โ โโโ youtube_player_state.dart
โโโ models/
โ โโโ player_config.dart # YouTube player config models
โโโ utils/
โ โโโ player_utils.dart # Player utility functions
โ โโโ youtube_web_actual.dart # Web iframe implementation
โ โโโ youtube_web_export.dart # Conditional export
โ โโโ youtube_web_stub.dart # Stub for non-web
โโโ widgets/
โโโ youtube_webview_player.dart # Desktop WebView player (localhost)
โโโ player_controls.dart # Seek overlay, loading, error widgets
โโโ player_bottom_actions.dart # Bottom action bar builder
โโโ player_settings_sheet.dart # Settings bottom sheet
โโโ player_settings_helper.dart # Settings helper
โโโ setting_item.dart # Individual setting toggle
โโโ fullscreen_player_page.dart # Fullscreen player page
๐ง Supported Formats #
YouTube URLs:
youtube.com/watch?v=... ยท youtu.be/... ยท youtube.com/embed/... ยท m.youtube.com/watch?v=... ยท Direct Video IDs
Video Files: MP4 ยท MOV ยท AVI ยท MKV ยท WebM ยท M4V ยท 3GP ยท FLV ยท WMV
โ FAQ #
Q: I get "Error 153" on Windows Desktop.
A: This is handled automatically. The package serves YouTube via http://localhost to bypass the restriction.
Q: I get "Nuget is not installed" on Windows.
A: Run winget install Microsoft.NuGet and restart your IDE.
Q: MP4 videos don't play on Windows.
A: Add WindowsVideoPlayer.registerWith() in your main() before runApp().
Q: Does it work on macOS/Linux?
A: Desktop support uses InAppWebView which primarily supports Windows. macOS/Linux support depends on flutter_inappwebview platform availability.
๐ค Contributing #
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License #
This project is licensed under the MIT License โ see the LICENSE file for details.
๐จโ๐ป Author #
Ahmed Mohamed Alam ยท GitHub: @ahmedalam782
๐ Dependencies #
- youtube_player_flutter โ YouTube player for mobile
- flutter_inappwebview โ WebView for Desktop YouTube
- video_player โ Flutter's official video player
- chewie โ Video player controls
- flutter_bloc โ State management
- video_player_win โ Windows MP4 support