youtube_player_flutter 5.2.0+1 copy "youtube_player_flutter: ^5.2.0+1" to clipboard
youtube_player_flutter: ^5.2.0+1 copied to clipboard

outdated

Flutter plugin for playing or streaming inline YouTube videos using the official iFrame player API. This plugin supports both Android and iOS.

YOUTUBE PLAYER FLUTTER

pub package Build Status licence Download 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,
    initialVideoId: "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,
    initialVideoId: "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
  • RemainingDuration
  • CurrentPosition
  • PlayPauseButton
  • PlaybackSpeedButton
  • ProgressBar
YoutubePlayer(
    context: context,
    initialVideoId: "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,
    initialVideoId: "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 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 2019 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.
    * Neither the name of Google Inc. nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

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.
1372
likes
40
pub points
99%
popularity

Publisher

verified publishersarbagyastha.com.np

Flutter plugin for playing or streaming inline YouTube videos using the official iFrame player API. This plugin supports both Android and iOS.

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

data_connection_checker, flutter, webview_flutter

More

Packages that depend on youtube_player_flutter