Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController will not automatically dismiss movie after finish playing (ios 6)

I may not have worded my title very well, maybe more correct to say my NSNotification isn't dismissing my movie's view after it's done playing. I've found others with this problem but no solutions, seems like it might be a problem with iOS 6 which is what I'm running.

After the video is done playing, you need to press "Done" to dismiss but I want it to dismiss automatically since I will be using MPMovieControlStyleNone once I get this sorted out. Here's my code with the unused sections stripped out: `

#import "MovieViewController.h"

@interface MovieViewController ()

@end

@implementation MovieViewController

@synthesize moviePlayer = _moviePlayer;

- (IBAction)playMovie:(id)sender
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"TestMovie" ofType:@"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:NO];
}

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

@end`
like image 660
robertfiorentino Avatar asked Oct 08 '12 17:10

robertfiorentino


1 Answers

Had this problem as well To fix in moviePlayBackDidFinish just add

player.fullscreen = NO;

before removing view from superview

like image 96
Jasen Avatar answered Oct 16 '22 08:10

Jasen