Flutter Youtube Player Plugin to Play Video without API Key

You are currently viewing Flutter Youtube Player Plugin to Play Video without API Key
Flutter Youtube Player

Flutter Youtube Player Plugin to Play Video without API Key

Flutter youtube player plugin for playing or streaming YouTube videos inline using the official iFrame Player API.

Supported Platforms:

  • Android
  • iOS For web support, use youtube_player_iframe. In future, this package will extend youtube_player_iframe.

Use this package as a library

Depend on it
Run this command:
With Flutter:

flutter pub add youtube_player_flutter

This will add a line like this to your package’s pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  youtube_player_flutter: ^8.0.0

Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:youtube_player_flutter/youtube_player_flutter.dart';

Example

Flutter Youtube Player
Flutter Youtube Player

Salient Features

  • Inline Playback
  • Supports captions
  • No need for API Key
  • Supports custom controls
  • Retrieves video meta data
  • 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
  • Fit Videos to wide screens with pinch gestures
See also  Shifting TabBar in Flutter

The plugin uses flutter_inappwebview under-the-hood.

Since flutter_inappwebview relies on Flutter’s mechanism for embedding Android and iOS views, this plugin might share some known issues tagged with the platform-views label.

Requirements

  • Android: minSdkVersion 17 and add support for androidx (see AndroidX Migration)
  • iOS: --ios-language swift, Xcode version >= 11

Setup

iOS 

No Configuration Needed
For more info, see here

Android

Set minSdkVersion of your android/app/build.gradle file to at least 17.

For more info, see here

Note: Although the minimum to be set is 17, the player won’t play on device with API < 20 (19 if Hybrid Composition is enabled). For API < 20 devices, you might want to forward the video to be played using YouTube app instead, using packages like url_launcher or android_intent.

Using Youtube Player

YoutubePlayerController _controller = YoutubePlayerController(
    initialVideoId: 'iLnmTe5Q2Qw',
    flags: YoutubePlayerFlags(
        autoPlay: true,
        mute: true,
    ),
);

YoutubePlayer(
    controller: _controller,
    showVideoProgressIndicator: true,
    videoProgressIndicatorColor: Colors.amber,
    progressColors: ProgressColors(
        playedColor: Colors.amber,
        handleColor: Colors.amberAccent,
    ),
    onReady () {
        _controller.addListener(listener);
    },
),

For FullScreen Support

If fullscreen support is required, wrap your player with YoutubePlayerBuilder

YoutubePlayerBuilder(
    player: YoutubePlayer(
        controller: _controller,
    ),
    builder: (context, player){
        return Column(
            children: [
                // some widgets
                player,
                //some other widgets
            ],
        );
    ),
),

Playing live stream videos

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

Flutter Youtube Player Demo
Flutter Youtube Player Demo
YoutubePlayerController _controller = YoutubePlayerController(
    initialVideoId: 'iLnmTe5Q2Qw',
    flags: YoutubePLayerFlags(
      isLive: true,
    ),
);

YoutubePlayer(
    controller: _controller,
    liveUIColor: Colors.amber,
),

Want to customize the player?

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

See also  Card Swipping Feature like Tinder in Flutter

Some of the widgets bundled with the plugin are:

  • FullScreenButton
  • RemainingDuration
  • CurrentPosition
  • PlayPauseButton
  • PlaybackSpeedButton
  • ProgressBar
YoutubePlayer(
    controller: _controller,
    bottomActions: [
      CurrentPosition(),
      ProgressBar(isExpanded: true),
      TotalDuration(),
    ],
),

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

Full Example 

YoutubePlayerController _controller;

@override
void initState(){
    _controller = YoutubePlayerController(
        initialVideoId: 'iLnmTe5Q2Qw',
        flags: YoutubePlayerFlags(
            mute: false,
            autoPlay: true,
        ),
    );
    super.initState();
}

@override
Widget build(BuildContext context){
    return YoutubePlayer(
       controller: _controller,
       showVideoProgressIndicator: true,
       videoProgressIndicatorColor: Colors.amber,
       progressColors: ProgressColors(
          playedColor: Colors.amber,
          handleColor: Colors.amberAccent,
       ),
       onReady: () {
          print('Player is ready.');
       },
    );
}

Quick Links

See also  Tags Input Textfield in Flutter

Download 

Download APKs from above(in badge) and try the plugin. APKs are available in Assets of Github release page.

Limitation 

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

Credit

This project is developed by sarbagyastha
Download this project from the below link.
https://github.com/sarbagyastha/youtube_player_flutter/archive/refs/heads/master.zip
You can visit original source page from the below link:
https://github.com/sarbagyastha/youtube_player_flutter

Spread the love

Leave a Reply