Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Rotating a video with iPhone Simulator


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!
  • 4
  • 3
1 Solution
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).
carvalhaesAuthor Commented:
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?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

carvalhaesAuthor Commented:
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'
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.

carvalhaesAuthor Commented:
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.
Because this part changed in iOS 4. Compare with other examples you have and see them working.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now