2

I'm trying to use MPMoviePlayerController to play a video from bundle and it says "Use of undeclared identifier 'MPMoviePlayerController'". Do I need to import any library to use this class ? Also, I'd like to know how to NOT play it in full screen and how to choose the size of the box where it'll be played.

The code:

NSString *url = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
moviePlayer.shouldAutoplay=YES;
CGRect videoRect = CGRectMake(0, 0, 300, 250); 
moviePlayer.view.frame = videoRect;
[self.view  addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
Charles
  • 50,943
  • 13
  • 104
  • 142
user2303633
  • 39
  • 1
  • 8

1 Answers1

0

You need to import/include the movie player: MediaPlayer/MediaPlayer.h

Also, the MediaPlayer.framework must be added to your "Frameworks" folder in the XCode project.

To not play in fullscreen:

self.moviePlayer.shouldAutoplay=YES;
CGRect videoRect = CGRectMake(0, 0, 300, 250); // define the player's dimensions in compact mode here its 300 * 250
self.moviePlayer.view.frame = videoRect;
[self.view  addSubview:self.moviePlayer.view];
R3D3vil
  • 681
  • 1
  • 9
  • 22
  • Sorry, I'm a beginner, how can I add a framework ? Thank you. – user2303633 Oct 25 '13 at 20:40
  • Click on the project in navigator, go to build phases, in link binary with libraries section tap on the add icon and search for the library you want. You can add it manually as well, right click on frameworks in your project -> add files and navigate to the location (its at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks for me) – R3D3vil Oct 25 '13 at 21:07
  • Jus found it http://stackoverflow.com/questions/10546374/how-add-framework-to-project-on-xcode-4-3-2 – user2303633 Oct 25 '13 at 21:08
  • Now it makes a box, but it's empty! The video doesn't play.. I edited the code – user2303633 Oct 25 '13 at 21:15
  • Oh, moviePlayer must be a property. Now it's fine. Thanks again – user2303633 Oct 25 '13 at 21:24
  • Yes it is.. sorry i didnt make it clear in my answer! – R3D3vil Oct 28 '13 at 13:06