From 1b58b562530cf157eecdcba309684f8e31a8f468 Mon Sep 17 00:00:00 2001 From: Jacob Hutchings Date: Tue, 9 Jun 2020 10:23:49 -0600 Subject: [PATCH 1/2] Fix timing issue where ready callback fired before webview finished loading. --- lib/src/player/raw_youtube_player.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/src/player/raw_youtube_player.dart b/lib/src/player/raw_youtube_player.dart index 0cf08bc8..e5a53b1a 100644 --- a/lib/src/player/raw_youtube_player.dart +++ b/lib/src/player/raw_youtube_player.dart @@ -35,6 +35,7 @@ class _RawYoutubePlayerState extends State YoutubePlayerController controller; PlayerState _cachedPlayerState; bool _isPlayerReady = false; + bool _onLoadStopCalled = false; @override void initState() { @@ -94,7 +95,14 @@ class _RawYoutubePlayerState extends State webController ..addJavaScriptHandler( handlerName: 'Ready', - callback: (_) => _isPlayerReady = true, + callback: (_) { + _isPlayerReady = true; + if (_onLoadStopCalled) { + controller.updateValue( + controller.value.copyWith(isReady: true), + ); + } + }, ) ..addJavaScriptHandler( handlerName: 'StateChange', @@ -206,6 +214,7 @@ class _RawYoutubePlayerState extends State ); }, onLoadStop: (_, __) { + _onLoadStopCalled = true; if (_isPlayerReady) { controller.updateValue( controller.value.copyWith(isReady: true), @@ -315,12 +324,12 @@ class _RawYoutubePlayerState extends State player.cueVideoById(id, startAt, endAt); return ''; } - + function loadPlaylist(playlist, index, startAt) { player.loadPlaylist(playlist, 'playlist', index, startAt); return ''; } - + function cuePlaylist(playlist, index, startAt) { player.cuePlaylist(playlist, 'playlist', index, startAt); return ''; @@ -355,7 +364,7 @@ class _RawYoutubePlayerState extends State player.setPlaybackRate(rate); return ''; } - + function setTopMargin(margin) { document.getElementById("player").style.marginTop = margin; return ''; From 2d7ac78dfa3e4156d2ca519236311cd6670e8999 Mon Sep 17 00:00:00 2001 From: Jacob Hutchings Date: Tue, 9 Jun 2020 10:24:02 -0600 Subject: [PATCH 2/2] Try to fix fullscreen sizing issue on iPhones with unsafe areas (notch and bottom swiper areas). --- lib/src/player/youtube_player.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/player/youtube_player.dart b/lib/src/player/youtube_player.dart index 53c7b01f..4c2b7c59 100644 --- a/lib/src/player/youtube_player.dart +++ b/lib/src/player/youtube_player.dart @@ -289,6 +289,7 @@ class _YoutubePlayerState extends State { } Widget _buildPlayer({Widget errorWidget}) { + final EdgeInsets padding = MediaQuery.of(context).padding; return AspectRatio( aspectRatio: _aspectRatio, child: Stack( @@ -297,7 +298,7 @@ class _YoutubePlayerState extends State { children: [ Transform.scale( scale: controller.value.isFullScreen - ? (1 / _aspectRatio * MediaQuery.of(context).size.width) / + ? (1 / _aspectRatio * (MediaQuery.of(context).size.width - padding.right - padding.left - padding.bottom)) / MediaQuery.of(context).size.height : 1, child: RawYoutubePlayer(