Rotating a video with iPhone Simulator

Posted on 2010-09-03
Last Modified: 2013-11-25

I used this youtube video ( to make an application where an iPhone shows a video.
However, starting at 4:25, I used another code (the code of the video does not work with the current sdk).

Here's the code that i used:

- (IBAction)playMovie {
	NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MOVIE001" ofType:@"mov"]];  
	MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  
	// Register to receive a notification when the movie has finished playing.  
	[[NSNotificationCenter defaultCenter] addObserver:self  
	if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
		// Use the new 3.2 style API  
		moviePlayer.controlStyle = MPMovieControlStyleNone;  
		moviePlayer.shouldAutoplay = YES;  
		[self.view addSubview:moviePlayer.view];  
		[moviePlayer setFullscreen:YES animated:YES];  
	} else {  
		// Use the old 2.0 style API  
		moviePlayer.movieControlMode = MPMovieControlModeHidden;  
		[moviePlayer play];  


Open in new window

The application is running ok but when I turn the iPhone simulator the video doesn't rotate.

What changes should I do in my code?

Thanks and sorry for my bad english!
Question by:carvalhaes
  • 4
  • 3
LVL 33

Expert Comment

ID: 33600349
Just found a nice article:
Play iPhone Movies in Portrait Mode with MPMoviePlayerController using Public API’s
You can download the source code - in the bottom of the article. It looks very nice.

The answer on your question is here:

You will see - people proposes to make new class derived from the movie controller and add method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);

Then use this class instead of the  MPMoviePlayerController.

BTW, please pay attention on movieFinishedCallback - that's answer on your question how to know when the show finished (if you are still looking for it).

Author Comment

ID: 33600380
could you explain better how can i "make new class derived from the movie controller and add method"?
how can i use this class instead of the MPMoviePlayerController?
LVL 33

Expert Comment

ID: 33600497
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 33600642
i try to open.

i put:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
inside the ibaction playmovie.
the video now is widescreen, but when i rotate the iphone simulator the video dont rotate.

and at .h, when i try to put
@interface MyMovieViewController : MPMoviePlayerViewController

i got an error cannot find interface declaration for 'MPMoviePlayerController', superclass of 'MyMovieViewController'
LVL 33

Expert Comment

ID: 33600744
MPMoviePlayerViewController - that's the point. It's a night here already. Maybe because of that, I missed that before.
Here you will find full program:
It has movieFinishedCallback (you asked in your first question about the subject).
It shows how to switch to the portrait mode:
[player setOrientation:UIDeviceOrientationPortrait animated:NO];

This app, when you will have it working, will be a base for other improvements.
Sorry, I just started from the code you proposed - MoviePlayer sample.


Author Comment

ID: 33600880
all right but i follow the steps of this link
but when i debug it, i can hear the sound but i cant see the video images.
i believe that is a sdk problem, because he made it with a older version than the mine.
LVL 33

Accepted Solution

pgnatyuk earned 500 total points
ID: 33600916
Because this part changed in iOS 4. Compare with other examples you have and see them working.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question