objective c MPMoviePlayerController wont work on iOS 4.3 - iphone

Ive got this code from an ebook tutorial on embedding MPMoviePlayerController from a VIEW object but it just dont work at all on iOS 4.3, it just gives me a black screen. I've tried looking at other sources and they have the same source code. Can anyone help me on finding what is the problem in this code.
Thanks
- (IBAction)playMovie:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"shawarma" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[player.view setFrame: movieHolder.bounds];
[movieHolder addSubview: player.view];
[player play];
}
My VIEW object has a dimension of 400 x 300.

From the MPMoviePlayerController class reference guidelines Consider
a movie player view to be an opaque structure.
You can add your own custom subviews to layer content on top of the
movie but you must never modify any of its existing subviews.
In addition to layering content on top of a movie, you can provide
custom background content by adding
subviews to the view in the backgroundView
MPMoviePlayerController it self has a property view to present the video
Hope this LINK might help you

There is no issue with MPMoviePlayer and ios 4.3 i am working on an application that plays movie from a server and this is working fine for me. I request you to check
Path of you resource try some hardcode path.
Frame of the MoviePlayer.
Thanks

Related

Adding videos to application

I want to store large number of videos in my application's directory. Will it make my application slow? Or will it take time to launch the application. I am loading videos only when necessary.
It will make large size of your application which is not good...& it will also take time to launch in place of save all ur video u can make user to download that video from server and after that it will be saved in ur doc directory so ur app will be not of large size.............
Where is it located locally
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"videoname" ofType:#"mov" inDirectory:#""]];
and play with that
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
[player release];
EDIT:-
The exact answer to this question is NO, it will not make your App Slow,But yeah it ill take some time to load the videos in your App,Time will depend upon number of videos you are loading in your APP. The solution to this is you have to use blocks for ALAssetLibaries.
Have a look on this ALAssetLibary Apple's class reference.
It may help you if not do contact me. Thanks :)

Getting a black screen when trying to play a movie

When i'm trying to play a movie on my iPhone, it isn't work. I dont know why.. searched here and all over the internet, try 5 different codes, but still can't get it to work. I'm new to Obj-C, so please be patient.
I just want the movie to play and when the movie is done, to exit the player. also, at the beginning I dont want it to show a black screen, I want to see the first frame of the video instead. is it possible?
-(void)playTheMovie
{
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"C061381" ofType:#"mp4" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
}
Thanks!
Most probably you are messing up with the URL.
Check out Movie player sample project from apple
https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
Run it first to confirm its functionality and then
Replace its movie with yours and change the extension and path name in the code
if it works copy the code to your project..

Xcode : Auto PlayVideo at start up

i want to play a short video as soon as the application launches. It's a short video and a light application so i do not expect any serious delays. However my problem is that although my code works fine wheni test it as an IBAction, it doesn't work when i paste it anywhere else like ViewDidLoad, awakeFromNib, ApplicationDidFinishedLaunching. I am searching all day long for tutorials that work in Xcode 4.2 (ARC enabled) but i couldn't find anything that worked.
Here is my code:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"testmovie" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//playercontroller.movieControlMode=MPMovieControlModeHidden;
[playercontroller.moviePlayer play];
playercontroller = nil;
If anybody can provide a tutorial or sample code, i would be extremly grateful!
Thanks in advance.
take out movie player and just use
[playercontroller play];
if it needs releasing do so as well

MediaPlayerViewController rotates into view before play

My MediaPlayerViewController developed this funny thing of rotating into view! My whole app is landscape based, but the MediaPlayerViewController seems to rotate from portrait to landscape and when finished the previous view would then also rotate from portrait into its original landscape orientation. This will not happen in a small test app. Only when the app becomes complicated. I have tried preloading the movie, doesn't help, i have tried didRotatefromInterfaceOrientation, nothing. I have my supported orientations set and to return UIInterfaceOrientationIsLandscape. My code for the movie if that might help:
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"BearA-least" ofType:#"mov"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentModalViewController:moviePlayer animated:NO];
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer.moviePlayer play];
I'm new to developing and have been struggling with this problem for a while. Any input would be greatly appreciated. I've seen people having similar problems with views rotating.
As I see, you're using MediaPlayerViewController and presenting it using presentModalViewController
MoviePlayerViewControllers are usually displayed using [self presentMoviePlayerViewControllerAnimated:(PlayerViewController)]
As I can see, you're preventing your user from controlling the playback -> MPMovieControlStyleNone
Hint: You might also want to set the movieSourceType property on your MoviePlayerController.
For controlling the orientation in a way as you're trying to achieve, I would suggest you to subclass MPMoviePlayerViewController and listen for notifications sent by the MPMoviePlayer on the various movie playback events.

Adding video to an iPhone application

How do I add a video to an iPhone app. using iPhone SDK 3.2.5?
I dont see the actual video but I can hear it playing.
Here is the code:
-(void) viewDidLoad{
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"Facebook" ofType:#"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[super viewDidLoad];
}
First off – find out what video format you are having. I assume it's not the one supported by iPhones.
So when you learn this you can go ahead and look for a third party player that is able to play back your video. I'm sure there are a lot of them there. Recommendation from me – try using VLC.
If you want to use default videos app on your iPhone (which, of course, is way better than any other alternative) you can try out Windows & Mac application WALTR 2: https://softorino.com/waltr/windows-guides/how-transfer-videos-to-iphone-without-itunes. It adapts any video & music for iPhone playback and pushes them to your default app on an iPhone.
You need to set the frame for you MPMoviePlayerController and add it to your view:
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[self.view addSubview:theMovie.view];