Some problem with MPMoviePlayerController using in ipad application - iphone

I am using MPMoviePlayerController in Ipad application. Video is not showing but audio comes, same code working well for Iphone
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"video" ofType:#"mp4"];
movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[IntroMovie play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
Please suggest me
Thanks
Miraaj

You must add the movie view to an existing view like this within view controller for sample:
[self.view addSubview:IntroMovie.view]

Is your iPad application a separate target from the iPhone application?
If so, did you remember to add the video to the resources copied into the iPad-application bundle?
If you didn't, drag it into the “Copy Bundle Resources” build phase within the iPad-application target.

In the new SDK you need to use a MPMoviePlayerViewController to present the video, not just a MPMoviePlayerController:
iPhone Dev Center

Related

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

objective c MPMoviePlayerController wont work on iOS 4.3

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

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];

Video not showing in iPhone Simulator (but I can hear audio from the video)

I am new to xcode, interface builder, and the iphone simulator. I am trying to play a movie/video in xcode on the click of a button (which is very straightforward). I am using xcode 3.2.4 and iphone simulator 4.1.
When I launch the iPhone simulator and click the button to launch the video, the audio plays, but the video is hidden. It's as if the video is behind the tab bar (this is part of a tab bar application). I am not sure how to make the video play in front.
Here's the code:
-(IBAction)launchVideo2:(id)sender{
NSString *movieFile;
MPMoviePlayerController *moviePlayer;
movieFile = [[NSBundle mainBundle]
pathForResource:#"IGDIs_Video_Picture_Naming_iPhone" ofType:#"mp4"];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath: movieFile]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playMediaFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[moviePlayer play];
}
-(void)playMediaFinished:(NSNotification*)theNotification
{
MPMoviePlayerController *moviePlayer=[theNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
}
Any suggestions would be great!
should be using the MPMoviePlayerViewcontroller
see apple documentation
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
It doesn't look like you have added the movie view to your main view. You'll need to add something like:
...
[[moviePlayer view] setFrame:[self view] bounds]];
[[self view] addSubview:[moviePlayer view]];
[moviePlayer play];
}
before playing it. I'm assuming that the a launchVideo2 method is in a UIViewController that owns the main view. You might have to change [self view] to suit your code to correspond to the view where you want the movie to play.
In my experience, video won't display in the sim. However, audio will. (Which is an improvement, since previously neither would play.)
Try running the app on the device. If the video doesn't display there, post here and we'll work through the issue.
You have a probably unrelated memory issue there:
In your first method, you don't release the player, which is a local variable.
In your second method, you release the player, that you don't own.
Proper memory management (ie best practice), you would do this with an ivar.

Why does MPMoviePlayerController work in the simulator, but not the device?

I'm having trouble getting MPMoviePlayerController to work on the device. It runs fine in simulator, playing a five-second video and then sending the appropriate callback (myMovieFinishedCallback:) to the view controller. When it runs on the device, the movie never shows up, even though I can trace through [player play] with no problems. myMovieFinishedCallback: is never called, and there are no errors. All the right resources are being copied. Any idea what's going on?
Here's the code I use to create and use the player,
Update: I've switched over to using MPMoviePlayerViewController. On the device the movie still does not play, I just get the spinning progress wheel indefinitely. The controls also flash briefly even though I've set the player to MPMovieControlStyleNone - anybody know how I can fix this? The movie is five seconds and about 1.5 MB if that makes any difference.
Update: Other movie files work, but I can't figure out how to make mine work. I've tried it as a .mov and a .mp4 and the settings seem to be right. Any idea what would cause the MPMoviePlayer to show a progress wheel forever on the device only?
- (void) playMovie
{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"myMovie"
ofType:#"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
playerViewController.view.frame = movieView.frame;
[movieView addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
Your code works fine for me, so there are two possibilities that come to mind (there may be others):
You movieView has not been properly initialized or has not had its frame set so that it's visible.
The video format of the video you're displaying isn't supported on the device.
I would try using a different video. Maybe one you can confirm you've played on the device before. Here's the little demo project I threw together: http://www.cimgf.com/files/PlayMovie.zip