0
votes

I'm trying to display a video using MPMoviePlayerController, but I can't manage to make it works. My video is on my server. So I'm trying to display it this way :

-(void) playMovieAtURL: (NSURL*) theURL {
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
    moviePlayer.view.frame = self.view.bounds;
    moviePlayer.controlStyle = MPMovieControlModeDefault;
    moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    moviePlayer.fullscreen = YES;

    [self.view addSubview:moviePlayer.view];
    [moviePlayer prepareToPlay];
    [moviePlayer play];
}

moviePlayer is a property of my viewController. The URL given is correct (tested in safari). My video is a .mov video.

When my function is called, I'm just having a black screen. Controls don't appear, and I think that the video doesn't load because in the status bar of the app, the network activity indicator is not displayed.

Any help is welcome.

EDIT

I've just noticed that trying to reach the video from the device's safari app result this :enter image description here

EDIT 2

My video is 480 × 850, and MPMoviePlayerController only support video up to 640 x 480. So it can't be played with this framework. Do I have to resize my video, or is there another frameworks that I can use to displayed it? I just need a very simple player...

2

2 Answers

1
votes

// you can do like this

 -(void)playMovie:(id)sender
 {
   NSURL *url = [NSURL URLWithString:
  @"http://www.xxxx.com/movie.mov"];

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

}

// The Target-Action 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];
}
}
1
votes

Do it this way:

-(void)playMovieAtURL:: (NSURL*) url
{

    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];
    [moviePlayer play];
    [self.view bringSubviewToFront:moviePlayer.view];
}


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