YoutubePlayerController class

Controls a youtube player, and provides updates when the state is changing.

The video is displayed in a Flutter app by creating a YoutubePlayerIFrame widget.

After YoutubePlayerController.close all further calls are ignored.

Constructors

YoutubePlayerController({required String initialVideoId, YoutubePlayerParams params = const YoutubePlayerParams()})
Creates YoutubePlayerController.

Properties

hashCode int
The hash code for this object.
no setterinherited
initialVideoId String
The Youtube video id for initial video to be loaded.
final
invokeJavascript Future<void> Function(String function)
Can be used to invokes javascript function.
getter/setter pair
metadata YoutubeMetaData
MetaData for the currently loaded or cued video.
no setter
onEnterFullscreen VoidCallback?
Called when player enters fullscreen.
getter/setter pair
onExitFullscreen VoidCallback?
Called when player exits fullscreen.
getter/setter pair
params YoutubePlayerParams
Defines default parameters for the player.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<YoutubePlayerValue>
The stream that this controller is controlling.
no setter
value → YoutubePlayerValue
The YoutubePlayerValue.
no setter

Methods

add(YoutubePlayerValue data) → void
Updates YoutubePlayerController with provided data.
close() Future<void>
Closes YoutubePlayerController.
cue(String videoId, {Duration startAt = Duration.zero, Duration? endAt}) → void
This function loads the specified video's thumbnail and prepares the player to play the video. The player does not request the FLV until YoutubePlayerController.play or YoutubePlayerController.seekTo is called.
cuePlaylist(String list, {String listType = PlaylistType.playlist, int startAt = 0, int index = 0}) → void
Queues the specified list of videos. The list can be a playlist, a search results feed, or a user's uploaded videos feed. When the list is cued and ready to play, the player will broadcast a video cued event PlayerState.cued.
hideEndScreen() → void
Hide EndScreen
hidePauseOverlay() → void
Hides pause overlay i.e. related videos shown when player is paused.
hideTopMenu() → void
Hides top menu i.e. title, playlist, share icon shown at top of the player.
Hide Youtube Logo
listen(void onData(YoutubePlayerValue event)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<YoutubePlayerValue>
Listen to updates in YoutubePlayerController.
load(String videoId, {Duration startAt = Duration.zero, Duration? endAt}) → void
This function loads and plays the specified video.
loadPlaylist(String list, {String listType = PlaylistType.playlist, int startAt = 0, int index = 0}) → void
This function loads the specified list and plays it. The list can be a playlist, a search results feed, or a user's uploaded videos feed.
mute() → void
Mutes the player.
nextVideo() → void
This function loads and plays the next video in the playlist.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() → void
Pauses the currently playing video.
play() → void
Plays the currently cued/loaded video.
playVideoAt(int index) → void
This function loads and plays the specified video in the playlist.
previousVideo() → void
This function loads and plays the previous video in the playlist.
reset() → void
Resets the value of YoutubePlayerController.
seekTo(Duration position, {bool allowSeekAhead = true}) → void
Seeks to a specified time in the video.
setLoop(bool loop) → void
This function indicates whether the video player should continuously play a playlist or if it should stop playing after the last video in the playlist ends.
setPlaybackRate(double rate) → void
Sets the playback speed for the video.
setShuffle(bool shuffle) → void
This function indicates whether a playlist's videos should be shuffled so that they play back in an order different from the one that the playlist creator designated.
setSize(Size size) → void
Sets the size in pixels of the player.
setVolume(int volume) → void
Sets the volume of player. Max = 100 , Min = 0
showTopMenu() → void
Show top menu
stop() → void
Stops and cancels loading of the current video.
toString() String
A string representation of this object.
inherited
unMute() → void
Unmutes the player.

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.