MPMoviePlayerViewController Dismiss Without playing

102 views Asked by At

The problem video can be seen in : http://app.bowerchat.com/images/118_1435046739658.mp4

MPMoviePlayerViewController Dismissing immediately without play. What can be reason?Some videos are loaded nicely and playing.

How can i check the video can be played or not? I tried

NSLog(@"%lu",(unsigned long)self.mpController.moviePlayer.loadState);
        NSLog(@"%d",self.mpController.moviePlayer == nil);

Results always 0 - 0

MY Code to play video

 self.mpController = [[MPMoviePlayerViewController alloc] initWithContentURL:moveUrl];
        [self.mpController.moviePlayer prepareToPlay];
        NSLog(@"%lu",(unsigned long)self.mpController.moviePlayer.loadState);
        NSLog(@"%d",self.mpController.moviePlayer == nil);

        [parent presentMoviePlayerViewControllerAnimated:self.mpController];
2

There are 2 answers

0
Misha On

The reason could be that movie that has extention *.mp4 is actually of different type.

Also try to add the following:

self.mpController.moviePlayer.shouldAutoplay = YES;
[self.mpController.moviePlayer play];
0
Doro On

Try this snippet :

-(void)setupMovie
{
    NSURL *movieURL = [NSURL fileURLWithPath:movieURL];

    self.mpController =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    self. mpController.scalingMode = MPMovieScalingModeAspectFill;
    self. mpController.controlStyle = MPMovieControlStyleNone;
    self.mpController.view.frame = self.view.frame;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification  object:nil];

    [self.view addSubview:self.mpController.view];
    [self.mpController prepareToPlay];
}


- (void)moviePlayBackDidFinish:(MPMoviePlayerController *)player
{
    [self.mpController.view removeFromSuperview];
}

- (void)moviePlayerPlaybackStateDidChange:(NSNotification*)notification
{
    if (self. mpController.isPreparedToPlay) {
        [self. mpController play];
    }
}

And make sure movieURL is correct and video exist by this provided url