youtube / youtube-ios-player-helper

Lightweight helper library that allows iOS developers to add inline playback of YouTube videos through a WebView
Other
1.64k stars 681 forks source link

Wrong height with auto layout constraints #80

Open h-code opened 9 years ago

h-code commented 9 years ago

Hi,

In my app The YTPPlayer should resize depending on device size Unfortunately when running on iPad the width is correct but not the height.

I got the correct behaviour by patching the height and size [playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.height] forKey:@"height"]; [playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.width] forKey:@"width"];

instead of [playerParams setValue:@"100%" forKey:@"height"] [playerParams setValue:@"100%" forKey:@"width"]

Regards JM

hemantasapkota commented 9 years ago

Thanks for posting this fix. I was having the same problem. Cheers

bagusflyer commented 9 years ago

I have no problem.

Fl0p commented 9 years ago

:+1: Same issue for me

steps:

So i can't predict correct size and add it as params before autolayout Any ideas ?

Fl0p commented 9 years ago

Found a better workaround in YTPlayerView-iframe-player.html new resize function

    <script src="https://www.youtube.com/iframe_api"></script>
    <script>

    var resizePlayer = function() {

        var player = document.getElementById('player');
        var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || document.height;
        var height = window.innerHeight || document.documentElement.clientHeight|| document.body.clientHeight || document.width;

        player.style.width = width + 'px';
        player.style.height = height + 'px';
    };

    window.addEventListener('resize', resizePlayer);

    var player;

    YT.ready(function() {
      player = new YT.Player('player', %@);
      resizePlayer();
      window.location.href = 'ytplayer://onYouTubeIframeAPIReady';
    });

This will allow to resize playerView as usual (for example autolayout on rotation) And player will not stuck with size from params. Player will be resized automatically with webView

@iulukaya need a pull request ? or maybe merge https://github.com/youtube/youtube-ios-player-helper/pull/87 ?