Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen youtube video, rotation, and the status bar (iOS)

I came across an issue in my current project, so I spun up a simple app to see if I could isolate the problem. In my app delegate I hide the status bar.

[application setStatusBarHidden:YES animated:NO];

In my single view controller I have this code:

- (void)loadVideo
{
    // HTML to embed YouTube video
    NSString *youTubeVideoHTML = @"<html><head>\
    <body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";

    // Populate HTML with the URL and requested frame size
    NSString *html = [NSString stringWithFormat:youTubeVideoHTML, @"http://www.youtube.com/watch?v=VDRoBnL1gRg", 500, 500];

    // Load the html into the webview
    [self.webview loadHTMLString:html baseURL:nil];
}

The app is also set to autorotate.

Now, here's the problem: When I play the youtube video, enter fullscreen mode, rotate the device 90 degrees, and hit "Done" to exit fullscreen, the entire interface remains shifted down 20px as if it were accommodating a status bar. I noticed that when viewing a video in full screen, ios adds a status bar, so I'm guessing that's part of the issue. I've seen the problem occur with the native video player as well.

Any ideas?

like image 283
Michael Avatar asked Feb 10 '12 19:02

Michael


2 Answers

I used this YouTube embed method recently for my app Game Guide: Black Ops 2, and I was having this problem along with being shown the rootViewController when hitting the movie player's "done" button. Checking "Wants Full Screen" on the rootViewController fixed the 20 pixel shift, and to fix the rootViewController being displayed after pushing the "done" button I added this to the rootViewController which was adding a UIViewController (with tableView) as a child which was using [presentViewControllerAnimated:(BOOL) completion:nil] to show the ViewController with the YouTube Video Embed.

Now everything is working perfectly... check out the Videos tab in my app if you want to see how it behaves.

-(void)viewDidAppear:(BOOL)animated {
    NSLog(@"Main View viewDidAppear...");
    [super viewDidAppear:animated];
    [self dismissViewControllerAnimated:YES completion:nil];

}

ios youtube iphone rotation statusbar mpmovieplayerviewcontroller

like image 179
BananaM0ntana Avatar answered Oct 28 '22 11:10

BananaM0ntana


I had a similar problem.

I created views in storyboard. Checking Wants full Screen in layout section of view controller settings solved it for me.

like image 22
user1350188 Avatar answered Oct 28 '22 10:10

user1350188