Quitting MPMediaPlayerController view

121 views Asked by At

I am writing a simple method to start a streaming video full-screen and letting the user quit pressing the "Done" button. Problem is, I can't remove the MPMediaPlayerController view, or perhaps I am doing it the wrong way.

- (IBAction)playVideoButtonPressed:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://mysite.com/video.mov"];
    mp = [[MPMoviePlayerController alloc] initWithContentURL: url];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerPlaybackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

    if ([mp respondsToSelector:@selector(setFullscreen:animated:)]) {  
        mp.controlStyle = MPMovieControlStyleFullscreen;  
        mp.shouldAutoplay = YES;
        [self.view addSubview:mp.view];  
        [mp.view setTag:3];
        [mp setFullscreen:YES animated:YES];  
    }
    [[NSNotificationCenter defaultCenter] addObserver:self            
        selector:@selector(moviePlayBackDidFinish:) 
        name:MPMoviePlayerPlaybackDidFinishNotification
        object:mp];

    [mp play];
}

- (void)moviePlayBackDidFinish:(id)sender {
      NSLog(@"Quitting MoviePlayer");
      [mp.view removeFromSuperview];    
}

The idea is that the MPMediaPlayerController view is called clicking on a button in the app, and it is dismissed by clicking the "Done" video or when the video ends.

1

There are 1 answers

0
Fr4ncis On BEST ANSWER

I should have used MPMoviePlayerViewController.