YouTube Player Plugin for Flutter

Published on by Flutter News Hub

YouTube Player Plugin for Flutter

The YouTube Player Flutter plugin allows you to seamlessly integrate YouTube videos into your Flutter applications. It leverages the official YouTube iFrame Player API, providing inline playback, caption support, and more, without the need for an API key.

Setup

iOS:

  • No additional configuration required.

Android:

  • Set minSdkVersion to 17 in android/app/build.gradle.
  • Ensure support for androidx.

Basic Usage

Dart Code:

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

YoutubePlayer(
  controller: _controller,
  showVideoProgressIndicator: true,
  progressIndicatorColor: Colors.amber,
);

Customization

Custom Controls:

Use topActions and bottomActions to customize the player controls with built-in widgets like PlayPauseButton, ProgressBar, and more.

Dart Code:

YoutubePlayer(
  controller: _controller,
  bottomActions: [
    CurrentPosition(),
    ProgressBar(isExpanded: true),
    TotalDuration(),
  ],
);

Advanced Features

Live Stream Support:

Enable live stream video playback by setting isLive to true in YoutubePlayerFlags.

Dart Code:

YoutubePlayerController _controller = YoutubePlayerController(
  initialVideoId: 'your_live_video_id',
  flags: const YoutubePlayerFlags(
    isLive: true,
  ),
);

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

Limitations

  • Requires Android API level 20 or higher.

Example

Navigate to the following GitHub URL for a detailed example:

https://github.com/sarbagyastha/youtube_player_flutter/tree/master/packages/youtube_player_flutter/example

Flutter News Hub