Using MPMoviePlayerViewController in SDK 3.2 for iPad
Asked Answered
S

6

9

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,

Sheeree answered 7/2, 2010 at 20:16 Comment(1)
refer to devx.com/wireless/Article/44642/1954Glarus
F
19
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];    
Fief answered 4/3, 2010 at 7:29 Comment(1)
it works fine for all why don't for me...it plays only audio no visuals are therePolyandry
C
3

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

Casaleggio answered 10/3, 2010 at 1:11 Comment(0)
T
3

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.

Triode answered 9/4, 2010 at 18:6 Comment(0)
U
2

change this line:

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

to

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

you need the *

Ulund answered 11/3, 2010 at 18:29 Comment(0)
B
2

I've struggled all over the place with this - Apple's own MoviePlayer sample code doesn't play video, only audio. It actually took me ages to figure out that it was playing audio because the sample airplane video they supply has NO AUDIO TRACK!!! (So I click the button and get absolutely nothing.)

Thanks for all the suggestions here. I finally found https://developer.apple.com/library/ios/#qa/qa2010/qa1240.html and even that is an obscure-ish fix.

This works: in initAndPlayMovie after [mp release]:

[[self.moviePlayer view] setFrame:[window bounds]];// size to fit parent view exactly
[window addSubview:[self.moviePlayer view]];

Bon voyage and happy flying :)

Blakeney answered 27/11, 2010 at 9:51 Comment(0)
M
0

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

Midday answered 28/2, 2010 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.