MPMoviePlayer не удаляется из superview

Я использую следующий код для воспроизведения видео файлов в MPMoviePlayerController

  NSString* filePath = [[NSBundle mainBundle] pathForResource:@"one" ofType:@"mp4"];
    NSURL*  url = [NSURL fileURLWithPath:filePath];

    _movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [_movie.view setFrame:self.view.bounds];
    [self.view addSubview:_movie.view];
    _movie.fullscreen=YES;
    _movie.controlStyle=MPMovieControlStyleFullscreen;
    [_movie prepareToPlay];
    [_movie play];

а также

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(close:)name:MPMoviePlayerPlaybackDidFinishNotification object:_movie];

а также

- (void) close:(NSNotification *)notification {

    int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];

    if(reason == MPMoviePlaybackStateStopped) {

        NSLog(@"Stop");

    }
    else if (reason == MPMovieFinishReasonPlaybackEnded) {
        NSLog(@"Playback Ended ");
    }
    else if (reason == MPMovieFinishReasonUserExited) {

        NSLog(@"Exited");
        [_movie.view removeFromSuperview];
    }
    else if (reason == MPMovieFinishReasonPlaybackError) {
        //error
        NSLog(@"Error");
    }    
}

Я могу получить уведомление, и Movieplayer не удаляется из суперпредставления.

В чем может быть проблема??

1 ответ

Решение

Попробуйте выполнить следующие инструкции:

когда я слушаю MPMoviePlayerWillExitFullscreenNotification.

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(doneButtonClick:) 
                                             name:MPMoviePlayerWillExitFullscreenNotification 
                                           object:_movie];

И метод выбора:

-(void)doneButtonClick:(NSNotification*)aNotification{
  [_movie.view removeFromSuperview];
}

(или же)

Лучший способ использовать mpmovieplayerviewcontroller в следующем уроке

http://mobiledevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

Другие вопросы по тегам