youtube_player 3.5.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 97

Youtube Player Plugin #

pub package Build Status licence

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

Released New Youtube Player based on Official Iframe API

This plugin only supports Android. So, published a new plugin youtube_player_flutter which is an officially provided way of playing youtube videos, supporting both Android and iOS platforms.

Note: Will keep on maintaining this plugin too.

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
  • Supports Live Stream Videos

DEMO

New Features in v3.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:

dependencies:
  youtube_player: ^3.5.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

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

5. Playing livestream videos

Must set isLive property to true in order to play livestream videos.

YoutubePlayer(
    context: context,
    source: "ddFvjfvPnqk",
    quality: YoutubeQuality.HD,
    **isLive: true,**
),

Note: #

In scenario, where one need to navigate to next page and return. You'll need to pause the video before navigating, otherwise the video will keep on playing.

RaisedButton(
    child: Text("Next Page"),
    onPressed: () {
          _videoController.pause();
          Navigator.of(context).push(
               MaterialPageRoute(builder: (context) => NextPage()),
          );
    },
),

Didn't like the controls ? #

Don't worry, Got a solution for you. 😉 Set the playermode to NO_CONTROLS, then you can create your own custom controls using the controller obtained from callbackController property.

YoutubePlayer(
    context: context,
    source: "ddFvjfvPnqk",
    playerMode: YoutubePlayerMode.NO_CONTROLS,
    callbackController: (controller) {
      _videoController = controller;
      },
),

Details #

Read about all the available properties for the player here.

Example #

Example sources

Limitation #

Download #

Download apk and try the plugin.

Credit

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

License #

Copyright (c) 2019 Sarbagya Dhaubanjar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[3.5.0] - August 6, 2019

  • Dependencies updated
  • Fix for some videos not working
  • Fix for resolution selection bottom sheet overflow

[3.4.1] - April 23, 2019

  • [FIXED] Bugs with orientation changes.
  • [FIXED] onVideoEnded being called more than once sometimes.
  • [Feature Added] loop property added.

[3.4.0] - April 23, 2019

  • [FIXED] Issue #31.
  • [Feature Added] FullScreen on orientation change. This can controlled using new reactToOrientationChange property.
  • Dart Docs Added.

[3.3.0] - April 21, 2019

  • Added option to hide share button using hideShareButton property.

[3.2.2] - April 17, 2019.

  • [Fixed] Issues with onVideoEnded as #28.
  • [Feature Added] Support for 144p playback added, as requested in #27.
  • [Improved] Quality change uses Modal Bottom Sheet now.
  • Updated to latest dependencies.
  • Changed dart sdk constraint to >=2.1.0 <3.0.0.

[3.2.1] - April 12, 2019.

  • switchFullScreenOnLongPress property added. If set to true, long press on a video will switch fullscreen.

[3.2.0] - April 1, 2019.

  • Issue #21 fixed.
  • [IMPORTANT] Read Note section.

[3.1.1+3] - February 24, 2019.

  • Minor changes.

[3.1.1] - February 24, 2019.

  • [Improved] Reduced the footprint of the plugin by removing unnecessary dependencies.
  • [Feature Added] controlsTimeOut property is added.
  • Updated ExoPlayer to Version 2.9.6
  • Sharing videos through Youtube App to Example App.
  • Minor improvements.

[3.1.0] - February 19, 2019.

  • [Fixed] Manifest Merger error.
  • [Feature Added] startFullScreen property is added.
  • Upgraded dependencies.
  • Minor bug fixes.

[3.0.0] - February 16, 2019.

  • Breaking change. [controlsBackgroundColor] is removed. [controlsColor] property is now changed to class. This allows to color customize almost every interactive elements in the player.
  • New Feature. Supports for Live Stream Videos added.
  • Updated ExoPlayer to Version 2.9.5
  • [controlsActiveBackgroundOverlay] property added.
  • [Fixed] Minor bug with timers.
  • [Improved] Removed last traces of support library(in favor of Androidx).

[2.0.3] - February 4, 2019.

  • controlsBackground property now sets background overlay for play and pause.
  • [Fixed] Crashing on defining width.

[2.0.2] - 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.

example/README.md

youtube_player_example #

More Detailed Example

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _idController = TextEditingController();
  String id = "7QUtEmBT_-w";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              YoutubePlayer(
                context: context,
                source: id,
                quality: YoutubeQuality.HD,
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: TextFormField(
                  controller: _idController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Enter youtube \<video id\> or \<link\>"
                  ),
                ),
              ),
              RaisedButton(
                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:


dependencies:
  youtube_player: ^3.5.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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
share ^0.6.2+1 0.6.2+4
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test