Giter Site home page Giter Site logo

arbitrarymahi / youtube_player_flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sarbagyastha/youtube_player_flutter

0.0 0.0 0.0 25.81 MB

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

License: MIT License

Java 2.20% Ruby 4.73% Objective-C 2.67% Dart 90.40%

youtube_player_flutter's Introduction

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.

Improvements in Version 3.x.x

  • Faster fullscreen toggling.
  • Toggles fullscreen on orientation change.
  • Option to add own custom thumbnail.

Migrating to v 3.x.x

This version requires YoutubeScaffold as parent of the player in order to switch to full screen. See example for detail.

Note: YoutubeScaffold cannot have more than one YoutubePlayer as its descendants.

Also, all the player flags are now moved into YoutubePlayerFlags class.

Before v3.x.x

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    autoPlay: true,
    showVideoProgressIndicator: true,
    videoProgressIndicatorColor: Colors.amber,
),

Now in v3.x.x

YoutubePlayer(
    context: context,
    videoId: "iLnmTe5Q2Qw",
    flags: YoutubePlayerFlags(
      autoPlay: true,
      showVideoProgressIndicator: true,
    ),
    videoProgressIndicatorColor: Colors.amber,
),

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: ^3.0.0+1

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",
    flags: YoutubePlayerFlags(
      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",
    flags: YoutubePLayerFlags(
      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",
    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.

Resolving Conflict with webview_flutter

Since this plugin already includes webview_flutter, there's no need to add webview_flutter separately as dependency.

Just remove it from dependencies in pubspec.yaml and use WebView widget by importing

import 'package:youtube_player_flutter/youtube_player_flutter.dart';

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.

youtube_player_flutter's People

Contributors

sarbagyastha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.