Solved

Rotating a video with iPhone Simulator

Posted on 2010-09-03
7
1,162 Views
Last Modified: 2013-11-25
Hi.

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  
											 selector:@selector(moviePlayBackDidFinish:)  
												 name:MPMoviePlayerPlaybackDidFinishNotification  
											   object:moviePlayer];  
	
	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!
0
Comment
Question by:carvalhaes
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33600349
Just found a nice article:
Play iPhone Movies in Portrait Mode with MPMoviePlayerController using Public API’s
http://iphonedevelopertips.com/video/play-movies-in-portrait-mode-with-mpmovieplayercontroller-using-public-apis.html
You can download the source code - in the bottom of the article. It looks very nice.

The answer on your question is here:
http://stackoverflow.com/questions/3019200/how-to-rotate-an-mpmovieplayercontroller
http://stackoverflow.com/questions/2852872/mpmovieplayercontroller-fullscreen-quirk-in-ipad/3026039#3026039

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).
0
 

Author Comment

by:carvalhaes
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?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33600497
0
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

by:carvalhaes
ID: 33600642
i try to open.
FIRST LINK:

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
@end

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

Expert Comment

by:pgnatyuk
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.




0
 

Author Comment

by:carvalhaes
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.
0
 
LVL 33

Accepted Solution

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

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