adaptive_video_player 1.0.4 copy "adaptive_video_player: ^1.0.4" to clipboard
adaptive_video_player: ^1.0.4 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.

pub package Flutter Platforms License: MIT


โœจ 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

๐ŸŽž๏ธ 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: 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.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"/>

(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,
  ),
)

๐ŸŽ›๏ธ 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 #

  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 #

7
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

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.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

chewie, flutter, flutter_bloc, flutter_inappwebview, video_player, video_player_win, web, youtube_player_flutter

More

Packages that depend on adaptive_video_player