Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make MPMoviePlayerViewController start in landscape mode but still allow changes to orientation
    primarykey
    data
    text
    <p>There are a multitude of questions here relating to locking movie playback into landscape mode, or supporting landscape playback of movies using MPMoviePlayerViewController or MPMoviePlayerController. I already have landscape/portrait functionality, and I don't want to lock the playback to either mode.</p> <p>What I have is code which uses MPMoviePlayerViewController as the docs suggest, essentially:</p> <pre> MPMoviePlayerViewController* movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; [parentViewController presentMoviePlayerViewControllerAnimated:movieViewController]; </pre> <p>My app is mostly locked to portrait mode, but this code presents the movie controller modally in its own view, and supports both portrait and landscape orientations. All of which is very nice.</p> <p>Here is my problem though. 99% of the videos I will be presenting are landscape videos, and the above code starts the movie playback in portrait mode, because the user is (likely) holding the device in portrait mode.</p> <p>What I want is the behaviour of the native YouTube app; that when you present the movie controller, it first presents in landscape mode, which will prompt the user to change their device's orientation. If they later on want to rotate it back to portrait they are allowed to. When the movie is done (or dismissed), the movie view controller will be dismissed, and the device should be in portrait mode.</p> <p>It seems impossible to hide the status bar properly (it's tied to the full screen controls regardless of the state of 'hideStatusBar' before launching the movie), so it seems that getting the status bar to be in the right place also needs to be a part of this.</p> <p><strong>Edited to add debugging notes for status bar orientation</strong>: If I call <code>setStatusBarOrientation:UIInterfaceOrientationLandscapeRight</code> before launching the movie, the status bar is in the right place, but the system no longer calls <code>shouldAutorotateToInterfaceOrientation</code> in the same way.</p> <p>If I don't call <code>setStatusBarOrientation</code>, prior to the movie appearing I get the following sequence of calls:</p> <pre>shouldAutorotateToInterfaceOrientation(Portrait) shouldAutorotateToInterfaceOrientation(Portrait) shouldAutorotateToInterfaceOrientation(Portrait) shouldAutorotateToInterfaceOrientation(Right) shouldAutorotateToInterfaceOrientation(Portrait)</pre> <p>I answer YES only to the Right, and the movie launches in LandscapeRight, but with the status bar in the wrong place. Subsequent changes of device orientation generate exactly the <code>shouldAutorotateToInterfaceOrientation</code> calls you'd expect (e.g. if I rotate to Portrait, it asks me if it's okay to rotate to Portrait).</p> <p>If I do call <code>setStatusBarOrientation:UIInterfaceOrientationLandscapeRight</code>, I get the following sequence:</p> <pre>shouldAutorotateToInterfaceOrientation(Right) shouldAutorotateToInterfaceOrientation(Right)</pre> <p>Both of which I answer YES to. The status bar is in the right place, but I no longer get an calls to <code>shouldAutorotateToInterfaceOrientation</code> asking about Portrait mode. So if I rotate the device to Right, then back to Portrait, then back to Right, I see it call <code>shouldAutorotateToInterfaceOrientation(Right)</code> twice. Even stranger, if I rotate it all the way around to the Left orientation, I do get <code>shouldAutorotateToInterfaceOrientation(Left)</code> <strong>and from then on everything works fine</strong>. Which is most annoying.</p> <p>I think it must be a bug on the iOS side, and that's why the YouTube app doesn't use the animated UI rotation effects. Instead it hides the full screen controls, including the status bar, rotates invisibly in the background, and then re-shows the controls.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload