Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Rotating a video with iPhone Simulator

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

I used this youtube video (http://www.youtube.com/watch?v=j6922mZ0WUU) 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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: http://www.devx.com/wireless/Article/44642/1954
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 http://www.devx.com/wireless/Article/44642/1954
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 2000 total points
ID: 33600916
Because this part changed in iOS 4. Compare with other examples you have and see them working.

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

618 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