raginggoat
raginggoat

Reputation: 3600

View Size for YTPlayer

I am using the iOS YouTube Player helper (https://developers.google.com/youtube/v3/guides/ios_youtube_helper) and it works just fine but the preview image is not the size of my view and I can't figure out how to change it so it fits within the UIView I've created. How can I make it fill the view?

Here is what it looks like. enter image description here

Upvotes: 3

Views: 3227

Answers (4)

Joel Rubinsky
Joel Rubinsky

Reputation: 41

A bit late to the party, but since none of the other solutions worked for me, I solved it by constraining the webView / YTPlayerView to a 16:9 aspect ratio as that is the standard aspect ratio for YouTube videos according to this:

https://support.google.com/youtube/answer/6375112?co=GENIE.Platform%3DDesktop&hl=en

With your webView/playerView the same aspect ratio as the video, the preview image will display properly.

Upvotes: 0

Zou
Zou

Reputation: 315

You can reset webView size in the following method:

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
    //
   self.player.webView.bounds = CGRectMake(0, 0, self.player.bounds.size.width, self.player.bounds.size.height*1.5);

    [self.player.webView setNeedsDisplay];
}

Upvotes: 0

Zou
Zou

Reputation: 315

I find another solution. If you use YTPlayerView in a xib file, please make sure the following points.

1, Check 'Use Auto Layout'

2, DO NOT set the width and height value for YTPlayerView.

then the YTPlayerView will play normally.

Upvotes: 0

AppsIntheParkNYC
AppsIntheParkNYC

Reputation: 146

This solved it for me:

In the Assets folder there should be an html file named "YTPlayerView-iframe-player.html"

Replace the existing code between "style" tags as shown below and this will make sure the Player fills 100% of the YTPlayerView:

<style>
    body { margin: 0; width:100%%; height:100%%; }
    html { width:100%%; height:100%%; }
</style>

Hope this helps a bit! Have a great weekend!

Upvotes: 13

Related Questions