3

I am using YTPlayerView classes to play YouTube videos. Below is the code i am using to load video according to device screen size (large size for iPad and small size for iPhone). And it is working fine.

Problem -- When i change device mode to landscape, i want larger YTPlayerView then in portrait mode. For now video has same size for both screen modes.

- (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams {
NSDictionary *playerCallbacks = @{
                                  @"onReady" : @"onReady",
                                  @"onStateChange" : @"onStateChange",
                                  @"onPlaybackQualityChange" : @"onPlaybackQualityChange",
                                  @"onError" : @"onPlayerError"
                                  };
NSMutableDictionary *playerParams = [[NSMutableDictionary alloc] init];
[playerParams addEntriesFromDictionary:additionalPlayerParams];

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
    [playerParams setValue:@"551px" forKey:@"height"];
    [playerParams setValue:@"768px" forKey:@"width"];
}
else
{
    [playerParams setValue:@"250px" forKey:@"height"];
    [playerParams setValue:@"320px" forKey:@"width"];
}
-----
-----
}

I can not use this check to give larger size to view, because above code does not called in-between video play.

if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscape)

Do you people have any idea how to fix this problem? Or if there is any other solution using JavaScript and css as html string to webView.

JAL
  • 41,701
  • 23
  • 172
  • 300
Yogendra
  • 1,728
  • 16
  • 28

2 Answers2

4

YTPlayerView actually uses webview to play the viedo, so you can only use css or javascript to change the size. There should be an html file named "YTPlayerView-iframe-player.html" in the Assets folder.

here is the css sample:

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

I have used YTPlayer in my story board and have put proper contraints on it as i'm using autolayouts in my project. It's working fine for me in both landscape and portrait mode.. I think the solution to your issue is autolayouts

Fayza Nawaz
  • 2,256
  • 3
  • 26
  • 61