Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Done button not dismissing movie player

When pressing the done button the movie player dosen't dismiss the view and getting black instead. It works with fast forward and when the movie is finished but not when hitting the done button. What should I do?

-(void)playMovie:(id)sender
{

    UIButton *buttonThatWasPressed = (UIButton *)sender;
    buttonThatWasPressed.enabled = NO;

    NSString * str=[[NSBundle mainBundle]pathForResource:@"yo2" ofType:@"mov"];
    NSURL * url=[NSURL fileURLWithPath:str];
    MPMoviePlayerController * movieController=[[MPMoviePlayerController alloc]initWithContentURL:url];
    movieController.controlStyle=MPMovieControlStyleFullscreen;
    [movieController.view setFrame:self.view.bounds];
    [self.view addSubview:movieController.view];
    [movieController prepareToPlay];
    [movieController play];



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

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

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];

    _moviePlayer.controlStyle = MPMovieControlStyleDefault;
    _moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:_moviePlayer.view];
    [_moviePlayer setFullscreen:YES animated:YES];

}

- (void) moviePlayBackDonePressed:(NSNotification*)notification
{
    [_moviePlayer stop];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];


    if ([_moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [_moviePlayer.view removeFromSuperview];
    }
    _moviePlayer=nil;

    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 [self performSegueWithIdentifier:@"show" sender:self];
                             }];

}

- (void) moviePlayBackDidFinish:(NSNotification*)notification

{


    // Remove observer
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];







    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 [self performSegueWithIdentifier:@"show" sender:self];
                             }];

}

@end


    ```

Is it it a bug?