YoutubePlayerController class
Controls the youtube player, and provides updates when the state is changing.
The video is displayed in a Flutter app by creating a YoutubePlayer widget.
After YoutubePlayerController.close all further calls are ignored.
- Implemented types
Constructors
-
YoutubePlayerController.new({YoutubePlayerParams params = const YoutubePlayerParams(), ValueChanged<
YoutubeWebResourceError> ? onWebResourceError}) - Creates YoutubePlayerController.
- YoutubePlayerController.fromVideoId({required String videoId, YoutubePlayerParams params = const YoutubePlayerParams(), bool autoPlay = false, double? startSeconds, double? endSeconds})
-
Creates a YoutubePlayerController and initializes the player with
videoId
.factory
Properties
-
availablePlaybackRates
→ Future<
List< double> > -
This function returns the set of playback rates in which the current video is available.
The default value is 1, which indicates that the video is playing in normal speed.
no setter
-
currentTime
→ Future<
double> -
Returns the elapsed time in seconds since the video started playing.
no setter
-
duration
→ Future<
double> -
Returns the duration in seconds of the currently playing video.
Note that duration will return 0 until the video's metadata is loaded,
which normally happens just after the video starts playing.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
isMuted
→ Future<
bool> -
Returns true if the player is muted, false if not.
no setter
- metadata → YoutubeMetaData
-
MetaData for the currently loaded or cued video.
no setter
- onFullscreenChange ↔ void Function(bool isFullscreen)
-
Called when full screen mode for the player changes.
getter/setter pair
- params → YoutubePlayerParams
-
Defines player parameters for the youtube player.
final
-
playbackRate
→ Future<
double> -
This getter retrieves the playback rate of the currently playing video.
The default playback rate is 1, which indicates that the video is playing at normal speed.
no setter
-
playerState
→ Future<
PlayerState> -
Returns the state of the player.
no setter
-
playlist
→ Future<
List< String> > -
This function returns an array of the video IDs in the playlist as they are currently ordered.
By default, this function will return video IDs in the order designated by the playlist owner.
no setter
-
playlistIndex
→ Future<
int> -
This function returns the index of the playlist video that is currently playing.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
YoutubePlayerValue> -
A Stream of YoutubePlayerValue, which allows you to subscribe to changes
in the controller value.
no setter
- value → YoutubePlayerValue
-
The YoutubePlayerValue.
no setter
-
videoData
→ Future<
VideoData> -
Returns the
VideoData
for the currently loaded/playing video.no setter -
videoEmbedCode
→ Future<
String> -
Returns the embed code for the currently loaded/playing video.
no setter
-
videoLoadedFraction
→ Future<
double> -
Returns a number between 0 and 1 that specifies the percentage of the video that the player shows as buffered.
no setter
-
videoStateStream
→ Stream<
YoutubeVideoState> -
The stream for YoutubeVideoState changes.
no setter
-
videoUrl
→ Future<
String> -
Returns the YouTube.com URL for the currently loaded/playing video.
no setter
-
volume
→ Future<
int> -
Returns the player's current volume, an integer between 0 and 100.
Note that it will return the volume even if the player is muted.
no setter
- webViewController ↔ WebViewController
-
The
WebViewController
that drives the playerlatefinal
Methods
-
close(
) → Future< void> - Disposes the resources created by YoutubePlayerController.
-
cuePlaylist(
{required List< String> list, ListType? listType, int? index, double? startSeconds}) → Future<void> - Queues the specified list of videos. The list can be a playlist or a user's uploaded videos feed.
-
cueVideoById(
{required String videoId, double? startSeconds, double? endSeconds}) → Future< 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 playVideo or seekTo is called.
-
cueVideoByUrl(
{required String mediaContentUrl, double? startSeconds, double? endSeconds}) → Future< 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 playVideo or seekTo is called.
-
enterFullScreen(
{bool lock = true}) → void - Enters fullscreen mode.
-
exitFullScreen(
{bool lock = true}) → void - Exits fullscreen mode.
-
getCurrentPositionStream(
{Duration period = const Duration(seconds: 1)}) → Stream< Duration> -
Creates a stream that repeatedly emits current time at
period
intervals. -
init(
) → Future< void> - Loads the player with default params.
-
listen(
void onData(YoutubePlayerValue event)?, {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription< YoutubePlayerValue> - Listen to updates in YoutubePlayerController.
-
load(
{required YoutubePlayerParams params, String? baseUrl}) → Future< void> -
Loads the player with the given
params
. -
loadPlaylist(
{required List< String> list, ListType? listType, int? index, double? startSeconds}) → Future<void> - This function loads the specified list and plays it. The list can be a playlist or a user's uploaded videos feed.
-
loadVideo(
String url) → Future< void> -
Loads the video with the given
url
. -
loadVideoById(
{required String videoId, double? startSeconds, double? endSeconds}) → Future< void> - This function loads and plays the specified video.
-
loadVideoByUrl(
{required String mediaContentUrl, double? startSeconds, double? endSeconds}) → Future< void> - This function loads and plays the specified video.
-
mute(
) → Future< void> - Mutes the player.
-
nextVideo(
) → Future< 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
-
pauseVideo(
) → Future< void> - Pauses the currently playing video. The final player state after this function executes will be paused (2) unless the player is in the ended (0) state when the function is called, in which case the player state will not change.
-
playVideo(
) → Future< void> - Plays the currently cued/loaded video. The final player state after this function executes will be playing (1).
-
playVideoAt(
int index) → Future< void> - This function loads and plays the specified video in the playlist.
-
previousVideo(
) → Future< void> - This function loads and plays the previous video in the playlist.
-
seekTo(
{required double seconds, bool allowSeekAhead = false}) → Future< void> - Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, video cued, etc.), the player will play the video.
-
setFullScreenListener(
ValueChanged< bool> callback) → void - Sets the full screen listener.
-
setLoop(
{required bool loopPlaylists}) → Future< 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. The default behavior is that playlists do not loop.
-
setPlaybackRate(
double suggestedRate) → Future< void> - This function sets the suggested playback rate for the current video. If the playback rate changes, it will only change for the video that is already cued or being played. If you set the playback rate for a cued video, that rate will still be in effect when the playVideo function is called or the user initiates playback directly through the player controls. In addition, calling functions to cue or load videos or playlists (cueVideoById, loadVideoById, etc.) will reset the playback rate to 1.
-
setShuffle(
{required bool shufflePlaylists}) → Future< 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. If you shuffle a playlist after it has already started playing, the list will be reordered while the video that is playing continues to play. The next video that plays will then be selected based on the reordered list.
-
setSize(
double width, double height) → Future< void> - Sets the size in pixels of the
-
setVolume(
int volume) → Future< void> -
Sets the
volume
. Accepts an integer between 0 and 100. -
stopVideo(
) → Future< void> - Stops and cancels loading of the current video. This function should be reserved for rare situations when you know that the user will not be watching additional video in the player. If your intent is to pause the video, you should just call the pauseVideo function. If you want to change the video that the player is playing, you can call one of the queueing functions without calling stopVideo first.
-
toggleFullScreen(
{bool lock = true}) → void - Toggles fullscreen mode.
-
toString(
) → String -
A string representation of this object.
inherited
-
unMute(
) → Future< void> - Unmutes the player.
-
update(
{FullScreenOption? fullScreenOption, PlayerState? playerState, double? playbackRate, String? playbackQuality, YoutubeError? error, YoutubeMetaData? metaData}) → void - Creates new YoutubePlayerValue with assigned parameters and overrides the old one.
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.