youtube_player 2.0.0

Youtube Player Plugin #

pub package

A flutter plugin to play Youtube Videos "inline" without API Key in range of Qualities(240p, 360p, 480p, 720p and 1080p).

Salient Features #

  • Inline playback
  • Thumbnail Support
  • Youtube-like controls
  • Customizable Controls
  • Supports HD and Full HD quality
  • Playable through
  • No need for API Key and no Limitations


New Features in v2.x.x! #

  • Change video quality on-the-fly.
  • Share video with other apps.
  • Fast Forward and Rewind with double tap.
  • Tap-and-hold to enter and exit fullscreen.
  • Auto resize as per the video's aspect ratio.

Usage #

1. Depend

Add this to you package's pubspec.yaml file:

  youtube_player: ^2.0.0

2. Install

Run command:

$ flutter packages get

3. Import

Import in Dart code:

import 'package:youtube_player/youtube_player.dart';

4. Using Youtube Player

/// LOW = 240p
/// MEDIUM = 360p
/// HIGH = 480p
/// HD = 720p
/// FHD = 1080p
/// "source" can be either youtube video ID or link.
        context: context,
        source: "nPt8bK2gbaU",
        quality: YoutubeQuality.HD,
        // callbackController is (optional). 
        // use it to control player on your own.
        callbackController: (controller) {
            _controller = controller;

Details #

sourceSource of youtube video. Video ID or URLRequired.
contextBuildContext of parent.Required.
qualitySets quality for youtube videos.Required.
aspectRatioSets aspect ratio of player's containerOptional. Default = 16/9
widthSets width of player's containerOptional. Default = Screen width. Must be less than Screen Width.
controlsColorSets color of controls like play, pause, etc.Optional. Default = White
controlsBackgroundColorSets background color of controls like play, pause, etc.Optional. Default = Transparent
startAtSets the starting position of the video.Optional.
showThumbnailShows thumbnail when video is initializing.Optional. Default = true
keepScreenOnTriggers screen to be on when not in fullscreen.Optional. Default = true
showVideoProgressBarShows progressbar below the video.Optional. Default = true
playerModeSets player mode. YoutubePlayerMode.NO_CONTROLS hides the controls from player. Useful when custom controls are to be build.Optional. Default = YoutubePlayerMode.DEFAULT
onErrorCallback which reports error.Optional.
onVideoEndedCallback which reports end of video.Optional.
callbackControllerCallback which provides current Video Controller.Optional.

Example #

Example sources

Limitation #

  • Only Available for Android (Currently)

Todos #

  • Support for ios
  • Adaptive playback as per the internet bandwidth


This plugin is a fork of video_player, developed by @Flutter Team.

License #

Copyright 2019 Sarbagya Dhaubanjar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

[2.0.0] - February 3, 2019.

  • Breaking change. [context] property is required now.
  • Redesigned controls to match original YouTube experience.
  • Fast forward and Rewind feature added, on double tap.
  • Can now adjust video quality through player.
  • Can now share videos with other apps.
  • Size of player can be adjusted.
  • [FIXED] Stretching portrait videos.

[1.0.0] - February 1, 2019.

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.
  • AutoPlay property added.

[0.8.1] - January 29, 2019.

  • Minor bug fixes.

[0.8.0] - January 29, 2019.

  • (Fixed) Defining controller is optional now.
  • (Fixed) Video not disposing issue. Thanks to [@Y-ndm] for raising the issue.

[0.7.2] & [0.7.1] - January 26, 2019.

  • Minor Fixes.

[0.7.0] - January 26, 2019.

  • Video loads and plays lot more faster than in previous versions.
  • Availability of controller outside the player, for in-depth customizations and events access See Example
  • (FIXED) Aspect ratio and orientation problem in videos.
  • (UNDER THE HOOD) Optimized Youtube Stream Link generation.
  • (UNDER THE HOOD) Reduced dependencies. Significant reduction in code reference.
  • Added controls customization.

[0.6.1] - January 11, 2019.

  • (FIXED) Video continuing to play on background. Thanks to [@ParthAggarwal1996] for raising the issue.
  • Dependency Update

[0.6.0] - January 5, 2019.

  • Videos play faster now.
  • Shows video thumbnail on loading.
  • Changed dependency to 'http' in place of 'dio' in order to reduce amount of code reference.
  • Automatic Fallback to lower quality if higher qualities are not available.
  • (FIXED) 'Default Interface Methods are only supported...' error.
  • (FIXED) Control bar not showing on single tap(after loading).
  • (FIXED) Depreciated Warnings
  • Support for Live Stream Video Playback Added (but not playing yet, will be fixed in next update on finding workaround).

[0.5.0] - January 5, 2019.

  • Minor Changes.

[0.4.0] - January 4, 2019.

  • Fixed some bugs with controls and orientation change.

[0.3.0] - January 4, 2019.

  • ReadMe File Updated. Fixed some bugs.

[0.2.0] - January 3, 2019.

  • Updated Controls.

[0.1.0] - January 2, 2019.

  • Initial Release.


youtube_player_example #

More Detailed Example

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _idController = TextEditingController();
  String id = "nPt8bK2gbaU";

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
                context: context,
                source: id,
                quality: YoutubeQuality.HD,
                padding: const EdgeInsets.all(8.0),
                child: TextFormField(
                  controller: _idController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Enter youtube \<video id\> or \<link\>"
                onPressed: () {
                  setState(() {
                    id = _idController.text;
                child: Text("Play"),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  youtube_player: ^2.0.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:youtube_player/youtube_player.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (meta).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.6 1.1.7
screen ^0.0.4 0.0.5
share ^0.6.0 0.6.1+1
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8