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

1

10

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`
Cholecyst answered 8/10, 2012 at 17:35 Comment(0)
A
18

Had this problem as well To fix in moviePlayBackDidFinish just add

player.fullscreen = NO;

before removing view from superview

Avarice answered 11/10, 2012 at 18:14 Comment(1)
I need it reverse. I want MPMoviePlayerController should not be dismiss automatically. User can dismiss it using Done buttonViolence

© 2022 - 2024 — McMap. All rights reserved.