iosmpmovieplayercontrollermpmovieplayermovieplayer

issue playing video in iOS sdk MPMoviePlayerController


I am trying to play video in iPhone, following is the code i have used.

It keep loading but video doesn't play, am i missing anything.

Player is launched but it sonly shows loading and never play the video.

I have also imported MediaPlayer/MediaPlayer.h

-(IBAction)play:(id)sender
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test_output" ofType:@"mov"];


NSURL *url = [NSURL URLWithString:
             moviePath];

_moviePlayer =  [[MPMoviePlayerController alloc]
                 initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:_moviePlayer];
[_moviePlayer prepareToPlay];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
     }


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

As shown in screenshot it keeps loading only


Solution

  • First, check whether your movie file is added to your project or not.

    Second, try creating path with fileURLWithPath. Replace your following code

    NSURL *url = [NSURL URLWithString:moviePath];
    

    with

    NSURL *url = [NSURL fileURLWithPath:moviePath];