views:

11085

answers:

10

I've developed an iPhone app that has been running MPMoviePlayer (pre 3.2 SDK) with no problems. I know this is a newbie question, but how do I get a movie to play in the new MPMoviePlayerViewController. I am only getting audio and wish to learn the new view controller. I've ported my whole app over to iPad and everything else works fine except for video. Could someone please show an example using the movie view controller? Any help would be appreciated.

Thanks,

A: 

I am pretty sure that its broken in simulator at present ! I get same behavior (no video but hear audio) with latest sdk and their own MPMoviePlayer sample code with Apples own video that Will play in iPad simulator using safari... So bottom line video plays on simulator-ipad inside of Safari but Not from an app using MpMoviePlayer class. Bug or feature, you decide. (I think its just broken). release notes for this version have lots of changes going on in MPMoviePlayer class...

me i
+6  A: 
NSURL* videoURL = [NSURL URLWithString:url];
MPMoviePlayerController   moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
//For viewing partially.....
[moviePlayer.view setFrame:CGRectMake(50, 200, (self.view.frame.size.width)-100 , 400)];
moviePlayer.view.backgroundColor = [UIColor grayColor]; 
[self.view addSubview:moviePlayer.view];    
Aneesh
thanks ...it worked for me,
Biranchi
A: 

I tried the code provide by KennyTM. Some time I get video, some time I don't any idea?

kpds
What? I did not provide any code.
KennyTM
@KennyTM - You edited a post by Aneesh who provided code.
willcodejavaforfood
+2  A: 

You need to use MPMoviePlayerViewController, not MPMoviePlayerController. Search the docs for MPMoviePlayerViewController.

Shizam
+1  A: 

change this line:

MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

to

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

you need the *

Tony
+1  A: 

Try this in your view controller:

MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];

This should get you started but check the MPMoviePlayerViewController Class Reference for detailed info.

Ferdinand Rios
+1  A: 

Sometimes if i click on "expand" button or "forward" button, video will stop playig and the MPMoviePlayerViewController modalVC will dismiss. Any help??

I got video ended with error as userinfo when tapping "expand screen" button !!!!!

A: 

The code provided by Ferdinand Rios worked for me in the iPhone 4 simulator, but the video doesn't auto rotate when the device is rotated to landscape. How do I make the video auto rotate?

joelhull
That depends on wether or not your containing controller supports those views.
Brandon
A: 

For rotation use

[moviePlayerViewController shouldAutorotateToInterfaceOrientation:YES];

Jose Angel Espinoza Portillo
A: 

refer to http://www.devx.com/wireless/Article/44642/1954

Forrest