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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.


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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
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 opening and reading files in the C programming language.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now