MPMoviePlayerController Endless Loading - iphone

I'm trying to play an MP4 file with the MPMoviePlayerController (also tried two m4v files, same problem), and finally got the video player to come up, but it just stays loading. Here's my code, executed on a button press:
NSString *videoFile = [[NSBundle mainBundle] pathForResource:#"attn8" ofType:#"mp4" inDirectory:#""];
NSURL *url = [NSURL fileURLWithPath:videoFile isDirectory:NO];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeFile;
//put on a whim from another answer, made no difference
[self.view addSubview:[player view]];
player.fullscreen = true;
[player prepareToPlay];
[player play];

Related

play video using url ios 6

I am struggling to play a video which is a url of the video file on a server. I have a view in which I display url from the web service. When I click the url(contained in a table cell) I want that a new view should appear with movie player on it playing the video. I have tried MPMoviePlayerViewController and also MPMoviePlayerController and various combinations of the two but I could not play the video on simulator. Currently I don't have a device so please consider simulator as well as device while answering. Currently i am using:
NSURL *url = [NSURL fileURLWithPath:filePath];
self.player= [[ MPMoviePlayerViewController alloc] initWithContentURL:url];
//self.player.navigationController.navigationBar.hidden = YES;
[self.player.moviePlayer prepareToPlay];
//self.player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.player.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.player.moviePlayer.fullscreen = NO;
[self presentModalViewController:self.player animated:NO];
[self.player.moviePlayer play];
filepath is a nsstring containing the video url.
Replace your this line : NSURL *url = [NSURL fileURLWithPath:filePath];
with this: NSURL *url=[NSURL URLWithString:filePath]; & then try.
My Code I am using MPMOVIEPLAYERVIEWCONTROLLER:
NSData *geturl = [[videoparsing objectAtIndex:btntag]objectForKey:#"iurl"];
myString = [[NSString alloc] initWithData:geturl encoding:NSASCIIStringEncoding];
NSLog(#"myString..%#",myString);
NSURL *fileURL=[NSURL URLWithString:myString];
NSLog(#"fileURL..%#",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
[moviePlayerController.moviePlayer play];
If video file is on server then
NSURL *url=[NSURL URLWithString:filePath];
other should be change movieSourceType to MPMovieSourceTypeStreaming :
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Also
self.player.moviePlayer.fullscreen = YES;
EDIT : Add :
self.player.moviePlayer.shouldAutoplay=YES;
remove :
[self.player.moviePlayer play];

Init and playing MPMoviePlayerController returns black screen

I am trying to play an mp4 video under iPhone Simulator 5.1 using some sample code from Xcode. I created both MPMovieViewController and MPMovieController, supply a local path which contains the mp4 and add it as subview to my root controller.
When I run it under iPhone Simulator, only back screen shown. I've tried a couple of suggestions of the same problem in SO but still it doesn't work.
Here's the code:
NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:#"VIDEO_CX75_01" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
player.view.frame = self.view.frame;
player.initialPlaybackTime = -1.0;
[player prepareToPlay];
[player play];
Where I am doing it wrong?
PS: I am on Xcode 4.3.2
I had the same problem, and I what I did was made player a strong property and synthesize it. It worked.
Should work in your case as well.!
Decide and use either MPMoviePlayerViewController or MPMoviePlayerController but not both.
NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:#"VIDEO_CX75_01" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
or
NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:#"VIDEO_CX75_01" ofType:#"mp4"]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
player.view.frame = self.view.bounds;
[self.view addSubview:player.view];
player.initialPlaybackTime = -1.0;
[player prepareToPlay];
[player play];

Play video stored in NSData

I am trying to play a video that is stored in an NSData object. I save the file to my applications temp folder and then try to play it, but all I get is a black screen. I can later browse to that folder and play the file, so I know that the file gets written and is supported.
This is my code:
NSString *urlString = [NSTemporaryDirectory() stringByAppendingPathComponent:#"test.m4v"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];
[moviePlayer prepareToPlay];
moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];
The only thing I can think of is that it takes some time for the file to get written, and the player tries to access it before it is done. Is that possible, and if so, how do I fix it?
When working with files you should tell the NSURL that the URL should point to a
file:
NSString *urlString = [NSTemporaryDirectory() stringByAppendingPathComponent:#"test.m4v"];
NSURL *url = [NSURL fileURLWithPath:urlString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];
[moviePlayer prepareToPlay];
moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

Application getting crashed on playing some sound file on iPhone application?

I am trying to play some music files on iPhone but after playing some files application getting crashed. It's random in nature and I am not getting any particular scenario can any one help me out on this?
My Code :
[player stop];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#",crr_PlayFile] ofType:#""]] error:nil];
[player setDelegate:self];
[player prepareToPlay];
[player play];
Is there any problem in my code.
Try to
[player release];
player = nil;
after your [player stop] call.

How to play video file in MPMOviePlayer?

I have implementing uITabbar application in which i want to play video file.Video file is playing but not seen.And simulator is Landscapmode bu MPMoviePlayer in Potrait mode.How to solve this problem.
Try to play the mp4 format.Because MPMoviePlayer Controller does not support many formats like avi.Here is the code which i implement.Hope it will help you and download any mp4 video file to play.
NSString *soundFilePath = [[NSBundle mainBundle]pathForResource:#"SoundFileName" ofType:#"mp4"];
//NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSURL *fileURL=[[NSURL fileURLWithPath:soundFilePath]retain];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[fileURL release];
[player play];