youtube_player_iframe 6.0.0 copy "youtube_player_iframe: ^6.0.0" to clipboard
youtube_player_iframe: ^6.0.0 copied to clipboard

Flutter port of the official YouTube iFrame player API. Supports Android, iOS, macOS & Web.

Youtube Player iFrame

Youtube Player iFrame

Pub Web Demo BSD-3 License Top Language GitHub issues Stars


๐ŸŽฌ Embed YouTube videos in your Flutter app โ€” inline, silky smooth, and with zero API key hassle. Powered by the official iFrame Player API, this plugin gives you near-complete control over playback without any of the headaches.

Demo Screenshot


โœจ Features #

๐ŸŽฏ What it does
๐Ÿ“บ Inline Playback Videos play right inside your app โ€” no pop-outs, no surprises
๐Ÿ”‘ No API Key Just plug and play. Seriously, no keys needed
๐Ÿ’ฌ Caption Support Full subtitle/caption support for accessibility
๐ŸŽฎ Custom Controls Build your own UI with YoutubeValueBuilder
๐Ÿ“Š Metadata Retrieval Fetch detailed info about any video
๐Ÿ”ด Live Stream Support Works with live streams too
โฉ Adjustable Playback Speed Slow-mo or 2ร— speed โ€” your call
๐Ÿ“‹ Playlist Support Native YouTube playlists + custom ones
๐Ÿ–ฅ๏ธ Smooth Fullscreen Auto-enters on landscape rotation, swipe up/down gesture support
๐Ÿ–ผ๏ธ Lazy Thumbnail Widget Shows a thumbnail first, creates the WebView only on tap โ€” perfect for lists
๐Ÿ•ต๏ธ Privacy-Enhanced Mode Uses youtube-nocookie.com by default so YouTube doesn't track your users
๐ŸŒ Multi-Platform Android, iOS, macOS, and Web โ€” all covered

๐Ÿ’ก Under the hood, this package uses webview_flutter.


๐Ÿ› ๏ธ Setup #

Before diving in, check out the webview_flutter docs for any platform-specific setup (Android permissions, iOS config, etc.).


๐Ÿš€ Quick Start #

1๏ธโƒฃ Create a controller #

final _controller = YoutubePlayerController(
  params: YoutubePlayerParams(
    mute: false,
    showControls: true,
    showFullscreenButton: true,
    privacyEnhancedMode: true, // uses youtube-nocookie.com (default)
  ),
);

_controller.loadVideoById(videoId: '<video-id>');  // โ–ถ๏ธ auto-play
_controller.cueVideoById(videoId: '<video-id>');   // โธ๏ธ ready but paused
_controller.loadPlaylist(list: [...]);             // โ–ถ๏ธ auto-play playlist
_controller.cuePlaylist(list: [...]);              // โธ๏ธ playlist, paused

๐Ÿฌ Shortcut: For a single video, use the convenience constructor:

final _controller = YoutubePlayerController.fromVideoId(
  videoId: '<video-id>',
  autoPlay: false,
  params: const YoutubePlayerParams(showFullscreenButton: true),
);

2๏ธโƒฃ Drop the player in your widget tree #

No wrapper widgets, no special scaffolding โ€” just drop it in and go. Fullscreen is handled internally. ๐ŸŽ‰

YoutubePlayer(
  controller: _controller,
  aspectRatio: 16 / 9,
  autoFullScreen: true, // ๐Ÿ“ฑ auto-enters fullscreen on landscape rotation
)

3๏ธโƒฃ Clean up when done #

@override
void dispose() {
  _controller.close();
  super.dispose();
}

๐Ÿ–ฅ๏ธ Fullscreen #

Fullscreen is smooth and just works on all platforms. The player intercepts the fullscreen button and handles the whole transition inside Flutter.

๐ŸŽฌ Trigger ๐Ÿ”€ What happens
Tap fullscreen button Animates to fullscreen
Rotate device to landscape Auto-enters fullscreen (autoFullScreen: true)
Swipe up in player Enters fullscreen
Swipe down in fullscreen Exits fullscreen
Back button / system gesture Exits fullscreen

๐Ÿ–ผ๏ธ Lazy Thumbnail (Great for Lists!) #

Got a list of videos? Don't create a WebView for every item โ€” that's expensive! ๐Ÿ’ธ

YoutubePlayerThumbnail shows a crisp thumbnail image and only spins up the WebView when the user taps. Smooth scrolling, happy users. ๐Ÿ˜Š

YoutubePlayerThumbnail(
  controller: YoutubePlayerController.fromVideoId(videoId: '<video-id>'),
  aspectRatio: 16 / 9,
  thumbnailQuality: ThumbnailQuality.high,
  thumbnailFormat: ThumbnailFormat.webp,
  // Optional: bring your own play icon ๐ŸŽจ
  // playIcon: const Icon(Icons.play_circle, size: 64, color: Colors.white),
)

Need just the thumbnail URL? No problem:

final url = YoutubePlayerController.getThumbnail(
  videoId: '<video-id>',
  quality: ThumbnailQuality.high,
  format: ThumbnailFormat.webp,
);

๐ŸŒฒ Expose the Controller Down the Tree #

Use YoutubePlayerControllerProvider to make the controller available to any descendant widget via context.ytController. No prop drilling needed! ๐Ÿ™Œ

YoutubePlayerControllerProvider(
  controller: _controller,
  child: Scaffold(
    body: Column(
      children: [
        YoutubePlayer(controller: _controller),
        const Controls(), // ๐ŸŽ›๏ธ can call context.ytController inside
      ],
    ),
  ),
);

๐ŸŽ›๏ธ Custom Controls #

YoutubeValueBuilder rebuilds whenever the player state changes โ€” making it super easy to build any custom playback control you dream up.

YoutubeValueBuilder(
  controller: _controller, // omit if using YoutubePlayerControllerProvider
  builder: (context, value) {
    return IconButton(
      icon: Icon(
        value.playerState == PlayerState.playing
            ? Icons.pause
            : Icons.play_arrow,
      ),
      onPressed: value.isReady
          ? () {
              value.playerState == PlayerState.playing
                  ? context.ytController.pause()
                  : context.ytController.play();
            }
          : null,
    );
  },
);

โš™๏ธ Player Parameters #

Tweak everything to match your app's vibe:

Parameter Type Default Description
mute bool false ๐Ÿ”‡ Start muted
showControls bool true ๐ŸŽฎ Show YouTube's built-in controls
showFullscreenButton bool false โ›ถ Show YouTube's fullscreen button
privacyEnhancedMode bool true ๐Ÿ•ต๏ธ Use youtube-nocookie.com
loop bool false ๐Ÿ” Loop the video
strictRelatedVideos bool false ๐Ÿ“Œ Related videos from same channel only
enableCaption bool true ๐Ÿ’ฌ Show captions by default
captionLanguage String 'en' ๐ŸŒ Caption language (ISO 639-1)
interfaceLanguage String 'en' ๐ŸŒ Player UI language (ISO 639-1)
color String 'white' ๐ŸŽจ Progress bar colour ('red' or 'white')
enableKeyboard bool web only โŒจ๏ธ Keyboard shortcuts
playsInline bool true ๐Ÿ“ฑ Inline playback on iOS
userAgent String? null ๐Ÿค– Custom WebView user agent
pointerEvents PointerEvents initial ๐Ÿ‘† CSS pointer-events on the player
origin String? null ๐Ÿ”’ Security origin for the iFrame API

Use copyWith to tweak an existing config without rebuilding from scratch:

final params = const YoutubePlayerParams(showControls: false);
final updated = params.copyWith(mute: true);

๐Ÿ”„ Migrating from YoutubePlayerScaffold #

YoutubePlayerScaffold is deprecated โ€” YoutubePlayer handles fullscreen on its own now. Here's how to update:

// โŒ Before (old way)
YoutubePlayerScaffold(
  controller: _controller,
  builder: (context, player) {
    return Scaffold(
      body: Column(children: [player, const Controls()]),
    );
  },
)

// โœ… After (new way)
YoutubePlayerControllerProvider(
  controller: _controller,
  child: Scaffold(
    body: Column(
      children: [
        YoutubePlayer(controller: _controller),
        const Controls(),
      ],
    ),
  ),
)

๐Ÿงช Try the Example App #

See everything in action โ€” check out the example app for complete working code.


๐Ÿค Contributors #