youtube_player_flutter 1.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new88

Youtube Player for Flutter #

pub package Build Status licence Download APK

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
  • No need for API Key
  • Supports custom controls
  • Supports Live Stream videos
  • Support for both Android and iOS
  • Adapts to quality as per the bandwidth
  • Fast Forward and Rewind on horizontal drag

The plugin uses forked version of 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.

Usage #

1. Depend

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

dependencies:
  youtube_player_flutter: ^1.1.0

2. Install

Run command:

$ flutter packages get

3. Import

Import in Dart code:

import 'package:youtube_player_flutter/youtube_player_flutter.dart';

4. Using Youtube Player

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

5. 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",
    isLive: true,
    liveUIColor: Colors.amber,
),

Didn't like the controls? #

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",
    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 apk 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.

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",
    autoPlay: 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: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
1.1.0 Apr 21, 2019 Go to the documentation of youtube_player_flutter 1.1.0 Download youtube_player_flutter 1.1.0 archive
1.0.1+1 Apr 12, 2019 Go to the documentation of youtube_player_flutter 1.0.1+1 Download youtube_player_flutter 1.0.1+1 archive
1.0.1 Apr 12, 2019 Go to the documentation of youtube_player_flutter 1.0.1 Download youtube_player_flutter 1.0.1 archive
1.0.0+2 Apr 12, 2019 Go to the documentation of youtube_player_flutter 1.0.0+2 Download youtube_player_flutter 1.0.0+2 archive
1.0.0+1 Apr 12, 2019 Go to the documentation of youtube_player_flutter 1.0.0+1 Download youtube_player_flutter 1.0.0+1 archive
1.0.0 Apr 12, 2019 Go to the documentation of youtube_player_flutter 1.0.0 Download youtube_player_flutter 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
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]
88
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/youtube_player.dart. (-0.50 points)

Analysis of lib/src/youtube_player.dart reported 1 hint:

line 388 col 53: Set literals were not supported until version 2.2, but this code is required to be able to run on earlier versions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
ytview >=0.0.7+2 <1.0.0 0.0.7+3
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test