youtube_player_flutter 5.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 96

YOUTUBE PLAYER FLUTTER

pub package Build Status licence Download apk-32 Download apk-64 Stars Top Language

Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API. Supports both Android and iOS platforms.

DEMO

Salient Features #

  • Inline Playback
  • Supports captions
  • No need for API Key
  • Supports custom controls
  • Supports Live Stream videos
  • Supports changing playback rate
  • Support for both Android and iOS
  • Adapts to quality as per the bandwidth
  • Fast Forward and Rewind on horizontal drag

The plugin uses webview_flutter under-the-hood to play videos.

Since webview_flutter relies on Flutter's new mechanism for embedding Android and iOS views, this plugin might share some known issues tagged with the platform-views and/or webview labels.

Setup #

iOS #

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

Android #

No configuration required - the plugin should work out of the box.

Using Youtube Player #

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    flags: YoutubePlayerFlags(
      autoPlay: true,
      showVideoProgressIndicator: true,
    ),
    videoProgressIndicatorColor: Colors.amber,
    progressColors: ProgressColors(
      playedColor: Colors.amber,
      handleColor: Colors.amberAccent,
    ),
    onPlayerInitialized: (controller) {
      _controller = controller;
      _controller.addListener(listener);
    },
),

Playing live stream videos #

Set the isLive property to true in order to change the UI to match Live Video.

Live UI Demo

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    flags: YoutubePLayerFlags(
      isLive: true,
    ),
    liveUIColor: Colors.amber,
),

Want to customize the player? #

With v5.x.x and up, use the topActions and bottomActions properties to customize the player.

Some of the widgets bundled with the plugin are:

  • FullScreenButton
  • TotalDuration
  • CurrentPosition
  • PlayButton
  • PlaybackSpeedButton
  • ProgressBar
YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    bottomActions: [
      CurrentPosition(),
      ProgressBar(isExpanded: true),
      TotalDuration(),
    ],
),

Didn't like the controls at all? #

Don't worry, Got a solution for you. 😉

Set the hideControls property to true, then you can create your own custom controls using the controller obtained from onPlayerInitialized property.

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    flags: YoutubePlayerFlags(
      hideControls: true,
    ),
    onPlayerInitialized: (controller) {
      //Create your own UI using this controller
      //on top of the player.
    },
),

Want to play using Youtube URLs ? #

The plugin also provides convertUrlToId() method that converts youtube links to its corresponding video ids.

String videoId;
videoId = YoutubePlayer.convertUrlToId("https://www.youtube.com/watch?v=BBAyRBTfsOU");
print(videoId); // BBAyRBTfsOU

Example #

More Detailed Example

Note #

Know more about the configuration options here.

Download #

Download apks from above(in badges) and try the plugin.

Limitation #

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

If you only want to target Android and need support for Android Kitkat or less, then you can use youtube_player.

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.

5.0.0+1 #

BREAKING CHANGES

  • Everything is modular now. See the docs for details.
  • Automatically switches to landscape on fullscreen mode.
  • Added proper display of errors and detects internet connection status.
  • Workarounds for iOS.
  • webview_flutter is swapped with ytview. If you've been using WebView widget, then consider changing import paths to ytview instead.
  • Added flags to enable/disable caption and looping.
  • Added flags to change caption language, start and end time of video.

4.1.0 #

  • Feature Added Button to change playback rate in player.
  • Added setPlaybackRate method to YoutubePlayerController. Issue #48
  • Improvement Playback behaviour synced with AppLifeCycle Issue #41

4.0.0+2 #

  • Fix error reports in LiveUI. PR#44
  • Added startAt property.

4.0.0+1 #

BREAKING CHANGES

  • YoutubePLayerScaffold has been removed.
  • Improved Orientations
  • Uses webview_flutter instead of ytview

3.0.0 #

  • BREAKING CHANGES See Migrating to 3.x.x for detail.
  • Faster fullscreen toggling.
  • Toggles fullscreen on orientation change. Issue #3.
  • Option to add own custom thumbnail.
  • FIXED Video stuck at unknown state Issue #24.
  • Added hideThumbnail and disableDragSeek flags. #27, #29.
  • FIXED Fullscreen toggle in iOS.
  • Minor UI improvements here and there.

2.0.0 #

  • FIXED iOS playback is fully functional. Issue #2
  • Added forceHideAnnotation property which hides the default YouTube annotation. Read Issue #17 for detail
  • Added option to mute player.

1.2.0 #

  • Added actions property, which can be used to add menus in top bar of video. See example for details.
  • Added option to hide fullscreen button.
  • FIXED Current position always showing 00:00 Issue #17

1.1.1+1 #

  • Updated dart constraint to >=2.2.0 <3.0.0*.
  • FIXED Parsing Exceptions.

1.1.1 #

  • Fix for issue #12.
  • WebView is now exported alongside YoutubePlayer.

1.1.0 #

  • Minor Improvements.
  • Built and tested on iOS device.
  • Migrated to AndroidX.
  • Removed warnings on iOS builds.

1.0.1+1 #

  • Added Travis CI.

1.0.1 #

  • FIXED Error while building for iOS.

1.0.0+2 #

  • FIXED Video pausing on tapped, when controls were hidden.

1.0.0+1 #

  • Added Download APK badge.

1.0.0 #

  • Initial Release.
  • Includes Dart Documentation.
  • Includes support for Live Videos.
  • Includes fast forward and rewind feature.

example/README.md

Youtube Player for Flutter Example #

More Detailed Example

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    flags: YoutubePlayerFlags(
         mute: false,
         autoPlay: true,
         forceHideAnnotation: true,
         showVideoProgressIndicator: true,
    ),
    videoProgressIndicatorColor: Colors.amber,
    progressColors: ProgressColors(
      playedColor: Colors.amber,
      handleColor: Colors.amberAccent,
    ),
    onPlayerInitialized: (controller) {
      _controller = controller;
      _controller.addListener(listener);
    },
),

Use this package as a library

1. Depend on it

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


dependencies:
  youtube_player_flutter: ^5.0.0+1

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

We analyzed this package on Oct 21, 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.

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 (cached_network_image).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
cached_network_image >=1.0.0 <2.0.0 1.1.2+1 2.0.0-rc
data_connection_checker >=0.3.0 <1.0.0 0.3.4
flutter 0.0.0
ytview >=1.0.0 <2.0.0 1.0.0+1
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
flutter_cache_manager 1.1.3
http 0.12.0+2
http_parser 3.1.3
meta 1.1.7
path 1.6.4
path_provider 1.4.0
pedantic 1.8.0+1
platform 2.2.1
sky_engine 0.0.99
source_span 1.5.5
sqflite 1.1.7+1
string_scanner 1.0.5
synchronized 2.1.0+1
term_glyph 1.1.0
typed_data 1.1.6
uuid 2.0.2
vector_math 2.0.8
Dev dependencies
flutter_test