Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API

Overview

Youtube Player IFrame

pub package licence Download Stars Top Language effective dart Web DEMO

Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API. The package exposes almost all the API provided by iFrame Player API. So, it's 100% customizable.

Note: This package only provides default youtube web player's skin. If you need Youtube Android player like player with gesture support, use youtube_player_flutter instead. youtube_player_flutter also uses this package as dependency. (Migration Pending)

Supported Platforms:

  • Android
  • iOS
  • Web

YOUTUBE PLAYER IFRAME

Click here for WEB DEMO

Salient Features

  • Inline Playback
  • Supports captions
  • No need for API Key
  • Supports custom controls
  • Retrieves video meta data
  • Supports Live Stream videos
  • Supports changing playback rate
  • Support for both Android and iOS
  • Adapts to quality as per the bandwidth
  • Exposes builders for building custom controls
  • Playlist Support (Both custom and Youtube's playlist)

For Web, Flutter's HtmlElementView. For Android & iOS, the package uses flutter_inappwebview under-the-hood.

Since flutter_inappwebview relies on Flutter's mechanism for embedding Android and iOS views, this plugin might share some known issues tagged with the platform-views label.

Requirements

  • Android: minSdkVersion 17 and add support for androidx (see AndroidX Migration)
  • iOS: --ios-language swift, Xcode version >= 11
  • Web: None

Setup

Web

No Configuration Required.

iOS

No Configuration Required.

Follow the guide here for complete iOS setup

Android

Set minSdkVersion of your android/app/build.gradle file to at least 17.

Follow the guide here for complete Android setup

Note: Although the minimum to be set is 17, the player won't play on device with API < 20 (19 if Hybrid Composition is enabled). For API < 20 devices, you might want to forward the video to be played using YouTube app instead, using packages like url_launcher or android_intent.

Using the player

YoutubePlayerController _controller = YoutubePlayerController(
    initialVideoId: 'K18cpp_-gP8',
    params: YoutubePlayerParams(
        playlist: ['nPt8bK2gbaU', 'gQDByCdjUXw'], // Defining custom playlist
        startAt: Duration(seconds: 30),
        showControls: true,
        showFullscreenButton: true,
    ),
);

YoutubePlayerIFrame(
    controller: _controller,
    aspectRatio: 16 / 9,
),

-------------- OR --------------

YoutubePlayerControllerProvider( // Provides controller to all the widget below it.
  controller: _controller,
  child: YoutubePlayerIFrame(
    aspectRatio: 16 / 9,
  ),
);

// Access the controller as: `YoutubePlayerControllerProvider.of(context)` or `controller.ytController`.

Want to customize the player?

The package provides YoutubeValueBuilder, which can be used to create any custom controls.

For example, let's create a custom play pause button.

YoutubeValueBuilder(
   controller: _controller, // This can be omitted, 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,
      );
   },
);

Available Methods

Methods available for YoutubePlayerController.

Method Description
play() Plays the currently cued/loaded video.
pause() Pauses the currently playing video.
stop() Stops and cancels loading of the current video.
nextVideo() Loads and plays the next video in the playlist.
previousVideo() Loads and plays the previous video in the playlist.
playVideoAt(index) Loads and plays the specified video in the playlist.
load(videoId, {startAt, endAt}) Loads and plays the specified video.
cue(videoId, {startAt, endAt}) Loads the specified video's thumbnail and prepares the player to play the video.
loadPlaylist(list, {listType, startAt, index}) Loads the specified list and plays it.
cuePlaylist(list, {listType, startAt, index}) Queues the specified list of videos.
mute() Mutes the player.
unMute() Unmutes the player.
setVolume(volume) Sets the volume of player.
seekTo(position, {allowSeekAhead}) Seeks to a specified time in the video.
setSize(size) Sets the size in pixels of the player.
setPlaybackRate(rate) Sets the playback speed for the video.
setLoop(loop) Enables or disables looping.
setShuffle(shuffle) Enables or disables shuffling playlist.
reset() Resets the controller.
convertUrlToId(url, {trimWhiteSpaces}) Converts fully qualified YouTube Url to video id.
getThumbnail(videoId, {quality, webp}) Grabs YouTube video's thumbnail for provided video id.
onEnterFullScreen() Called when player enters fullscreen.
onExitFullScreen() Called when player exits fullscreen.
invokeJavascript(function) Invoke custom javascript function.
hideTopMenu() Hides the title and share icons at the top of player (May violate YouTube's TOS. Use at your own risk.)
hidePauseOverlay() Hides the related videos overlay while player is paused (May violate YouTube's TOS. Use at your own risk.)

Youtube Player Parameters

All the available parameters.

Parameter Description
autoPlay Specifies whether the initial video will automatically start to play when the player loads. Default = true
mute Mutes the player. Default = false
captionLanguage Caption language. Default = 'en'
enableCaption Enables caption by default. Default = true
color Specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen. Default = red
showControls Indicates whether the video player controls are displayed. Default = true
enableKeyboard Enables or disables the player to respond to keyboard controls. Default = false
enableJavaScript Enables or disables the player to be controlled via IFrame or JavaScript Player API calls. Default = true
endAt Ends the playback in specified time.
showFullscreenButton Shows or hides the fullscreen button from displaying in the player. Default = false
interfaceLanguage Sets the player's interface language.
showVideoAnnotations Enables or disables video annotations to be shown by default. Default = true
loop Enables or disables the player to play the initial video again and again. Default = true
playlist Specifies a list of video IDs to be played after initialVideoId.
playsInline Controls whether videos play inline or fullscreen in an HTML5 player on iOS. Default = true
strictRelatedVideos Enabling ensure that related videos will come from the same channel as the video that was just played. Default = false
startAt Starts the video at specified time.
desktopMode The controls will be alike Youtube Desktop's controls.
useHybridComposition Enable Hybrid Composition

Limitation

For Android: Since the plugin is based on platform views. This plugin requires Android API level 19 or greater.

License

Copyright 2021 Sarbagya Dhaubanjar. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You might also like...

An application built using Flutter that can be used while playing board games if actual or physical dice is missing . This is a dual dice application.

diceee_utter A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Feb 3, 2022

Flutter plugin to simply integrate Agora Video Calling or Live Video Streaming to your app with just a few lines of code.

Agora UI Kit for Flutter Instantly integrate Agora video calling or video streaming into your Flutter application. Getting started Requirements An Ago

Dec 16, 2022

The simple Podcast playing app for Android & iOS, built with Dart & Flutter

The simple Podcast playing app for Android & iOS, built with Dart & Flutter

Anytime Podcast Player This is the official repository for the Anytime Podcast P

Dec 29, 2022

Tic Tac Toe game with single-player and multi-player options. Implemented minimax algorithm.

flutter_tic_tac_toe A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

Jan 1, 2022

Flutter plugin that saves images and videos to devices gallery

Gallery Saver for Flutter Saves images and videos from network or temporary file to external storage. Both images and videos will be visible in Androi

Nov 25, 2022

An API of the official Django polls tutorial with Dart-Frog 🐸

polls_api 📝 Description A polls api using dart_frog. localhost/polls localhost/polls/[id] ☢️ This is a sample project and dart_frog is currently expe

Sep 20, 2022

Integration test - Copy of the official Flutter integration test plugin

integration_test This package enables self-driving testing of Flutter code on de

Jan 5, 2022

A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter

A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter

Klutter A streaming client for the Komga self-hosted comics/manga/BD server targeting Android/iOS written in Dart/Flutter Background This is a project

Dec 7, 2022

An sample app demonstrating online radio streaming in flutter

An sample app demonstrating online radio streaming in flutter

Flutter Radio App Hey, This is an app demonstarting online radio streaming in flutter. Have a look. Demo Catch the demo in this video. If you like it,

Jun 28, 2022
Owner
Pratap Singh
Code = me
Pratap Singh
A flutter plugin to play Youtube Videos without API Key in range of Quality(144p, 240p,360p,480p,720p and 1080p).

Youtube Player Plugin This plugin is discontinued. Please use youtube_player_flutter which is an officially provided way of playing youtube videos, su

Sarbagya Dhaubanjar 120 Nov 13, 2022
A feature-rich cross-platform webview using webview_flutter for mobile and iframe for web. JS interop-ready.

A feature-rich cross-platform webview using webview_flutter for mobile and iframe for web. JS interop-ready. Getting started Gallery Basic usage Featu

null 2 Mar 17, 2022
A Flutter plugin that allows you to add an inline WebView.

native_webview A Flutter plugin that allows you to add an inline WebView. Motivation There is already a useful library for working with WebViews in Fl

hisaichi5518 46 Dec 14, 2022
A Video Player For Vimeo Videos in Flutter. This plugin allows us to play video from Vimeo and it supports Android and iOS platforms.

vimeo_video_player A Video Player For Vimeo Videos in Flutter. This plugin allow us to play video from vimeo and it's supports Android and iOS platfor

MindInventory 26 Dec 8, 2022
Youtube Clone App with GetX & Youtube Data Api V3 [MVC pattern]

Youtube App ✍?? Youtube App Clone with GetX & Youtube Data Api V3 [MVC pattern] ????‍?? Youtube App app is open-source Youtube App app for Android & i

null 6 Nov 6, 2022
Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.

HtmlWidget monorepo This repo contains the source code for everything HtmlWidget-related. Name Link flutter_widget_from_html_core flutter_widget_from_

Đào Hoàng Sơn 445 Jan 6, 2023
Flutter APP which fetches data from YouTube & Play Videos!😉

YouTube Video Player YouTube Video Player is built in FLUTTER ?? & DART ?? Motivation As this project uses YouTube Data API v3, motivation for this pr

Abhishek Rajendra Wagh 7 Apr 12, 2022
A Flutter App To Download Videos From YouTube In Mp3 Format

Flutter_YouTube_MP3 App A Simple app To Download mp3 Videos From YouTube ❤️ Found this project useful? If you found this project useful, then please c

Sheraz Mahar 24 Dec 19, 2022
Flutter youtube downloader - A Windows App made in Flutter to download mp3 or mp4 from a Youtube video

youtube_downloader A Windows App made in Flutter to download mp3 or mp4 from a Y

Sakshham Bhagat 3 Nov 30, 2022
Koel Player, the official mobile app for Koel

Koel Player The mobile app for Koel, which provides a complete mobile app experience and doesn't have the limitations of the mobile web version. Suppo

Koel 227 Dec 27, 2022