YoutubePlayer class

A widget to play or stream YouTube videos using the official YouTube IFrame Player API.

In order to play live videos, set isLive property to true in YoutubePlayerFlags.

Using YoutubePlayer widget:

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..addListener(listener);
   },
)
Inheritance

Constructors

YoutubePlayer({Key? key, required YoutubePlayerController controller, double? width, double aspectRatio = 16 / 9, Duration controlsTimeOut = const Duration(seconds: 3), Widget? bufferIndicator, Color? progressIndicatorColor, ProgressBarColors? progressColors, VoidCallback? onReady, void onEnded(YoutubeMetaData metaData)?, Color liveUIColor = Colors.red, List<Widget>? topActions, List<Widget>? bottomActions, EdgeInsetsGeometry actionsPadding = const EdgeInsets.all(8.0), Widget? thumbnail, bool showVideoProgressIndicator = false})
Creates YoutubePlayer widget.
const

Properties

actionsPadding EdgeInsetsGeometry
Defines padding for topActions and bottomActions.
final
aspectRatio double
Defines the aspect ratio to be assigned to the player. This property along with width calculates the player size.
final
bottomActions List<Widget>?
Adds custom bottom bar widgets.
final
bufferIndicator Widget?
Overrides the default buffering indicator for the player.
final
controller YoutubePlayerController
A YoutubePlayerController to control the player.
final
controlsTimeOut Duration
The duration for which controls in the player will be visible.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
liveUIColor Color
Overrides color of Live UI when enabled.
final
onEnded → void Function(YoutubeMetaData metaData)?
Called when player had ended playing a video.
final
onReady VoidCallback?
Called when player is ready to perform control methods like: play(), pause(), load(), cue(), etc.
final
progressColors ProgressBarColors
Overrides default colors of the progress bar, takes ProgressColors.
final
progressIndicatorColor Color
Overrides default color of progress indicator shown below the player(if enabled).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showVideoProgressIndicator bool
Defines whether to show or hide progress indicator below the player.
final
thumbnail Widget?
Thumbnail to show when player is loading.
final
topActions List<Widget>?
Adds custom top bar widgets.
final
width double?
Defines the width of the player.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<YoutubePlayer>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

convertUrlToId(String url, {bool trimWhitespaces = true}) String?
Converts fully qualified YouTube Url to video id.
getThumbnail({required String videoId, String quality = ThumbnailQuality.standard, bool webp = true}) String
Grabs YouTube video's thumbnail for provided video id.