Skip to content

Commit

Permalink
Merge pull request #249 from revroad-dev/master
Browse files Browse the repository at this point in the history
Timing and Sizing Issue
  • Loading branch information
sarbagyastha authored Jun 22, 2020
2 parents a44edaf + 2d7ac78 commit 8c1a46f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/src/player/raw_youtube_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
YoutubePlayerController controller;
PlayerState _cachedPlayerState;
bool _isPlayerReady = false;
bool _onLoadStopCalled = false;

@override
void initState() {
Expand Down Expand Up @@ -94,7 +95,14 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
webController
..addJavaScriptHandler(
handlerName: 'Ready',
callback: (_) => _isPlayerReady = true,
callback: (_) {
_isPlayerReady = true;
if (_onLoadStopCalled) {
controller.updateValue(
controller.value.copyWith(isReady: true),
);
}
},
)
..addJavaScriptHandler(
handlerName: 'StateChange',
Expand Down Expand Up @@ -206,6 +214,7 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
);
},
onLoadStop: (_, __) {
_onLoadStopCalled = true;
if (_isPlayerReady) {
controller.updateValue(
controller.value.copyWith(isReady: true),
Expand Down Expand Up @@ -316,12 +325,12 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
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 '';
Expand Down Expand Up @@ -356,7 +365,7 @@ class _RawYoutubePlayerState extends State<RawYoutubePlayer>
player.setPlaybackRate(rate);
return '';
}
function setTopMargin(margin) {
document.getElementById("player").style.marginTop = margin;
return '';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/player/youtube_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class _YoutubePlayerState extends State<YoutubePlayer> {
}

Widget _buildPlayer({Widget errorWidget}) {
final EdgeInsets padding = MediaQuery.of(context).padding;
return AspectRatio(
aspectRatio: _aspectRatio,
child: Stack(
Expand All @@ -297,7 +298,7 @@ class _YoutubePlayerState extends State<YoutubePlayer> {
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(
Expand Down

0 comments on commit 8c1a46f

Please sign in to comment.