๐ŸŽฅ Adaptive Video Player

The only Flutter video player that supports YouTube + Direct videos on ALL platforms with one widget.

A comprehensive Flutter video player package that seamlessly handles both YouTube videos and direct video URLs with adaptive player selection. Works beautifully on Android, iOS, macOS, Windows, Linux, and Web.

pub package Flutter Platforms License: MIT


โšก 10-Second Quick Start

AdaptiveVideoPlayer(
  config: VideoConfig(
    videoUrl: "https://youtu.be/VIDEO_ID",
  ),
);

(Just drop it in and it automatically adapts to YouTube or direct MP4/HLS streams!)


๐ŸŽฅ Demo

Android iOS
Android Demo iOS Demo
Windows macOS
Windows Demo macOS Demo
Web
Web Demo

โœจ Features

๐ŸŽฌ Adaptive Video Player

  • Smart Detection โ€” Automatically detects YouTube vs direct video URLs
  • Unified API โ€” Single AdaptiveVideoPlayer widget 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: true to use WebViews on Android/iOS)
  • Settings panel with runtime toggles
  • Fullscreen mode with state preservation
  • Safe External Link Handling (Opens YouTube external URLs in system browser)
  • Live Stream Support with "LIVE" indicator and Viewer Count

๐ŸŽž๏ธ Normal Video Player

  • Supports MP4, MOV, AVI, MKV, WebM, M4V, 3GP, and more
  • Network streaming, local file, and in-memory bytes playback
  • Built-in advanced adaptive controls
  • Error handling with customizable messages
  • Quality Selection (Resolution/source picker)
  • Subtitle/CC Support (SRT/VTT formats)
  • Custom UI Builders (controlsBuilder, subtitleBuilder)

๐Ÿ†š Why Adaptive Video Player?

Here is how adaptive_video_player compares to other popular video packages:

Feature adaptive_video_player youtube_player_flutter chewie video_player
YouTube + MP4 URLs โœ… โŒ โŒ โŒ
Desktop Support โœ… โŒ โš ๏ธ โš ๏ธ
Live Stream Support โœ… โŒ โŒ โŒ
Unified API โœ… โŒ โŒ โŒ
Quality Selection โœ… โŒ โŒ โŒ
External Link Safety โœ… โŒ โŒ โŒ

๐Ÿ–ฅ๏ธ 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 (package:web) YouTube native controls

Why localhost on Desktop (Windows, macOS, Linux)? YouTube blocks iframe embedding from local files like data: and file:// (Error 153). Serving via http://localhost provides a trusted origin that YouTube allows.


๐Ÿ“ฆ Installation

Add to your pubspec.yaml:

dependencies:
  adaptive_video_player: ^1.2.3

๐Ÿ”’ 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"/>

(Required) For playing http:// video URLs AND for using forceDesktopMode: true on Android, you must 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,
  ),
)

Live Stream Example

AdaptiveVideoPlayer(
  config: VideoConfig(
    videoUrl: 'https://www.youtube.com/watch?v=YOUR_LIVE_VIDEO_ID',
    isLive: true,
    viewerCount: '1.2K', // Optional viewer count for the LIVE badge
  ),
)

๐ŸŽ›๏ธ Configuration Reference

VideoConfig

Property Type Default Description
videoUrl String required Video target URL
isFile bool false True if the URL is a local file path
isLive bool false Enables LIVE indicator and disables seek bar
viewerCount String? null Displayed when isLive is true
qualities List<VideoQuality>? null Available qualities or sources
subtitles List<SubtitleTrack>? null Available subtitle tracks
controlsBuilder AdaptiveControlsBuilder? null Custom controls overlay builder
subtitleBuilder SubtitleBuilder? null Custom subtitles UI builder
playerConfig YouTubePlayerConfig const YouTubePlayerConfig() YouTube specific settings

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
forceDesktopMode bool false Use WebView player on Android/iOS
allowExternalLinks bool true Open external links in system browser

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 & Smart YouTube/direct video detection
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ normal_video_player/
    โ”‚   โ”œโ”€โ”€ normal_video_player.dart        # Native video player component
    โ”‚   โ”œโ”€โ”€ adaptive_controls.dart          # Core UI controls overlay builder
    โ”‚   โ””โ”€โ”€ 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.


๐Ÿ”ฎ Roadmap (Future Features)

We are actively working to make this the ultimate video player. Upcoming features:

  1. Playlist Support: AdaptiveVideoPlaylist(videos: [...])
  2. Analytics Callbacks: onPlay, onPause, onCompleted, onError
  3. Picture in Picture (PiP): Native PiP support for Android & iOS.

(Got a feature request? Open an issue!)


๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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