Movie play error - nil string - ios

I am trying to play a movie in ios but i keep getting error.
My code:
-(IBAction)playMovie:(id)sender
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"big-buck-bunny-clip" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
[self.view addSubview:moviePlayerController.view];
//moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
the error is:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[NSURL
initFileURLWithPath:]: nil string parameter'

ok i got it .. i forgot to add the file in build phase ...

Related

how do i fix MPMoviePlayerViewController

i click on the button here is the code
//NSURL *url = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:self.urlFile];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
_moviePlayer.view.frame = CGRectMake(0, 0, 320, 300);
[_moviePlayer setFullscreen:YES animated:YES];
and it plays but when i press the Done button, here is the method
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
player.initialPlaybackTime = -1;
[player.view removeFromSuperview];
}
it looks like this
sorry dont have enough to post image
it has the black lining on the bottom and the play button disappears as well, how do i load it back to the point it was when the cell was pressed and came to the detailViewController

MP movie controller removes when done button is clicked in iphone

I am playing video in MPmovieController it works fine but player removes when complete video is played.I want that when user pressed done button then video should stop here is the code i am using.
NSURL*myURL=[NSURL fileURLWithPath:url];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:myURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
Try this one:
NSURL *fileURL=[NSURL URLWithString:[[array objectAtIndex:videoid] valueForKey:#"VideoUrl"]];
self.mpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:self.mpPlayer];
[self.mpPlayer.moviePlayer prepareToPlay];
self.mpPlayer.moviePlayer.shouldAutoplay=NO;
[self.mpPlayer.moviePlayer play];
- (void)moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer pause];
[self dismissMoviePlayerViewControllerAnimated];
// [moviePlayer.view removeFromSuperview];
}
may be it will help.
happy coding...
remove this line into your then it will work
[moviePlayerController.view removeFromSuperview];

Can't stop animation occurring in MPMoviePlayerController when done is pressed

I'm trying to prevent the transition animation that occurs when you exit a video in MPMoviePLayerController when the user presses done. I can stop it fine when the movie finishes on its own using the moviePlayBackDidFinish: notification but for some reason when I try it in the exact same way with the exitedFullscreen: notification (which responds to a done press) it doesn't work, as in, the animation occurs.
Here is the complete code, any help would be much appreciated.
-(void) playvideo
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"test" ofType:#"MOV"]];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
}
-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
moviePlayer.fullscreen = NO;
[moviePlayer.view removeFromSuperview];
}
- (void)exitedFullscreen:(NSNotification*)notification {
moviePlayer.fullscreen = NO;
[moviePlayer.view removeFromSuperview];
}
you can to remove animation using this code .
-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
[moviePlayer stop];
[moviePlayerController.view removeFromSuperview];
moviePlayer = nil;
}
- (void)exitedFullscreen:(NSNotification*)notification {
[moviePlayer stop];
[moviePlayerController.view removeFromSuperview];
moviePlayer = nil;
}

iOS streaming video error

I get following error:
2012-04-04 23:46:18.374 istiqlaltv[17121:e903] -[istiqlaltvViewController moviePlayBackDidFinish]: unrecognized selector sent to instance 0x6136ee0
2012-04-04 23:46:18.380 istiqlaltv[17121:e903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[istiqlaltvViewController moviePlayBackDidFinish]: unrecognized selector sent to instance 0x6136ee0'
This is code, I am very new in iOS, I just want to play a streaming video when you press the play button.
-(void)playVideo{
NSURL *url = [[NSURL alloc] initFileURLWithPath:#"http://blabla.com/playlist.m3u8"];
NSString *strVersion = [[UIDevice currentDevice] systemVersion];
float version = [strVersion floatValue];
if(version < 4.0){
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc] initWithContentURL:url];
themovie.scalingMode = MPMovieScalingModeAspectFill;
[themovie play];
}else{
MPMoviePlayerViewController *themovie = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:themovie.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:themovie];
}
}
-(void) moviePlayBackDidFinish:(NSNotification *)notification{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player stop];
[self dismissMoviePlayerViewControllerAnimated];
}
Any help?
You are missing the : in the moviePayBlackDidFinish: selector when you add your observer:
Should be:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:themovie.moviePlayer];
Note that the colon after the method name indicates that the method takes a parameter. You were getting the error because your code was looking for a method named moviePlaybackDidFinish that does not take a parameter, but no such method exists.

how iOS play the video by URL

I want to play a video by the URL. I see some sample,the codes like below:
NSString *movieFile= [[NSBundle mainBundle] pathForResource:#"android" ofType:#"mp4"];
videoURL=[[NSURL alloc] initFileURLWithPath:movieFile];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:videoURL];
It play only the local resource.I write some code like:
NSString* strurl =#"https://s3.amazonaws.com/adplayer/colgate.mp4";
videoURL=[NSURL fileURLWithPath:strurl];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:videoURL];
but there is nothing ... why..and how to play video by the url ?
In following code, I am playing a video over the internet from a movie file located on a web server. Dont forget to add MediaPlayer framework and include "MediaPlayer/MediaPlayer.h" in ViewController.h file.
On a button click use following code:
-(IBAction) playVideo:(id)sender
{
NSURL *url=[[NSURL alloc] initWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
Notification method:
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
if ([player respondsToSelector:#selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
Use the following code:
- (IBAction)playBtnPressed {
NSURL *url = [[NSURL alloc] initWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
//moviePlayer.shouldAutoplay=NO;
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlayBackDonePressed:(NSNotification *)notification {
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
moviePlayer = nil;
}
- (void)moviePlayBackDidFinish:(NSNotification *)notification {
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
}
Use following line in .h file and add MediaPlayer Framework in your project
import
Try
NSURL *url = [NSURL URLWithString: strurl];

Resources