MPMoviePlayer Orientation - iphone

I am playing MP3 audio via a URL using the MPMoviePlayer. But when it plays, it flips to Landscape layout, and I would like it to remain in portrait layout.
Any ideas?
Thanks,
John

You could use an ugly hack and place it in a UIWebView, but this functionality really should be in MPMoviePlayer.

Unfortunately, the movie player can only play movies in Landscape. You'll have to reencode your movies rotated to 480x320 instead of 320x480. After you play the movie, it changes the status bar's orientation, so you need to flip that back with setStatusBarOrientation:animated::
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

Related

iPhone rotation and full-screen video

I've encountered a strange issue, which I need help resolving. My app is always run in portrait mode - I explicitly want it to be that way. In one place in the app I have a UIWebView, which works just fine, as expected. This web view is not shown all the time but is dynamically added to the main view and removed based on user actions (i.e. it's only visible when I need it to).
Now, sometimes in this view I may have a youtube video. The WebView simply contains the <iframe> for the youtube embed. When a user clicks on the video preview frame in the webview, a full-screen video viewer is launched to play the video - which is just fine.
However if during the playback the user rotates the phone, the full-screen video player is rotated and the video is played in landscape mode. Now the video is stopped and the user presses "Done" button without rotating the phone back to portrait mode, the video player is closed and the user returns to my app - however now my layout is also rotated! Not just the video view, but the entire layout - with toolbar, navigation controller, etc.
I don't want any rotation! I just want everything in my app to remain in portrait mode! Moreover, now even if the phone is rotated back to portrait, the app stays in landscape mode.
Note that I only tested this in a simulator so far, as I currently don't have a physical phone to test. I created a simple (bad quality!) video (just filmed the simulator on my screen with an old phone camera) to demonstrate the issue - the video is here: http://shchuka.com/hosting/rotation_problem.mp4
Any ideas what I can do about it?
Add this in, or change it:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientation == UIInterfaceOrientationPortrait);
}
That will prevent all rotation and the app will only work in portrait mode. You can place the return statement within IF statements to allow rotation under certain circumstances.
I sometimes add views to the appDelegate window when I want them to be above everything else, and an annoying side-effect has been that I have to explicitly call my own rotation code as there is no VC as such to deal with it. On the plus side, it might mean that it could be ideal for your needs -
[[[[UIApplication sharedApplication] delegate] window] addSubview:myWebView];
...depending on your app's orientation, etc, before you load the view in the first place, you might need to rotate the webView before displaying it.

MPMoviePlayerController only rotate on fullscreen

I have a table view that contains an instance of MPMoviePlayerController as the table header and when the user presses my custom overlay button, the video expands to full screen. The aspect ratio of the video is such that in portrait mode it is very small, and I imagine most users will rotate to landscape.
The problem is that I want to allow rotation when the video is full screen but not when it exits. My underlying table does not support landscape. Is there a way to support rotation only when full screen? I thought this would be a standard component of MPMoviePlayerController.
I'm using SDK 5.0, but it was originally built with 4.3.
Have you tried subclassing the MPMoviePlayerController MPMoviePlayerViewController class, and overriding the method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (!self.fullscreen) {
return UIDeviceOrientationIsPortrait(interfaceOrientation);
}
return YES;
}

iPhone, playing a movie in landscape but return to portrait when movie is complete

Total Objective-C/XCode N00b here but I am attempting something, which I assume is simple. I have an app that is written for the iPhone, I don't allow auto orientation and only have the main interface locked into portrait. When the user plays a video in the app I would like to allow them to auto rotate the device from portrait and watch it in landscape (should they choose to do so, I don't want to force this). Once the user presses "Done", I would like to force them back into portrait (even if they are holding the device in landscape) as the interface is only laid out in that orientation.
I've tried using the MPMoviePlayerController and MPMoviePlayerViewController and I am not sure which will give me the leverage/methods I need. I am basically just looking to allow shouldAutorotateToInterfaceOrientation to return yes only when the MPMoviePlayerController view is visible.
Any help MUCH appreciated. Thanks.
I used this code example and it worked perfectly. I think you'll have to set the orientation in the super class.

MPMoviePlayerViewController orientation

I'm using cocos2d and i want to play a movie. For these purposes i've created MPMoviePlayerViewController and put it as a subview to [[CCDirector sharedDirector] openGLView]. The problem is that it appears in a vertical orientation.
In the application orientation is set to landscape:
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
How can i change the orientation of my player ?
Have a look at the cocos2d manual page about autorotation:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:autorotation
Basically you have to decide between two solutions:
Cocos2D handles orientation changes and you need to rotate the MPMoviePlayerViewController's view manually (e.g. using CGAffineTransformMakeRotation).
Cocos2D's opengl-view doesn't handle orientation changes and is inside a UIViewController that overrides shouldAutorotateToInterfaceOrientation and thus automatically rotates the view for you.

iPhone UIImagePicker Camera in Landscape Orientation

Is there any good way to set UIImagePicker to landscape orientation? I tried to call setStatusBarOrientation after presentModalViewController like following,
[self presentModalViewController:picker animated:YES];
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated: NO ];
However, the video duration view (00:00) on the right corner didn't rotate as orientation changed.
Unfortunately, according to the documentation, the image picker only supports portrait mode.
Apple doesn't support landscape for camera view. If you want anything shown as customised then add overlay view on it & transform that view to look as landscape view.
#Note:-overlay is also add as portrait thats why transformation needed.
I was able to create landscape camera view using the following code:
[self.view insertSubview:self.imagePicker.view atIndex:0];
self.imagePicker.view.transform =
CGAffineTransformScale (
CGAffineTransformTranslate(
CGAffineTransformMakeRotation(M_PI/2), -90, -15),
1.2,1.2)
;
Note that I am directly adding the imagePicker's view to the current view, not calling it as a modal.
self.imagePicker.view.transform seems to respond as expected to all CGAffineTransform function calls, though I can't speak to whether or not Apple approves of this method.