2012-10-10 1 views
1

"완료"버튼을 누르지 않고도 스스로 해제 할 영화를 얻으려고합니다. 나는 튜토리얼을 정확히 따르고 NSLogs를 삽입 할 때 NSNotification과 removeFromSuperview가 인식되고 있지만 영화가 끝나면 그대로 남아 있기 때문에 최근 iOS 6 문제라고 생각합니다. 여기에 내 코드입니다, 도와주세요 :removeFromSuperview가 내 영화 하위보기를 제거하지 않는 이유는 무엇입니까? Xcode

- (IBAction)playMovie:(id)sender 
{ 
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
             pathForResource:@"RomneyFlipSequence1" 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 
+0

이 문제를 해결 했습니까? 동일한 문제가 있습니다. –

+1

예, 전체 화면을 나가는 데는 문제가 있습니다. 이 줄을 추가해야합니다 : player.fullscreen = NO; [player.view removeFromSuperview]; – robertfiorentino

답변

1

플레이어를 전체 화면 모드로 전환했습니다. 다른 솔루션을 읽기

[_moviePlayer setFullscreen:YES animated:NO]; 

SO 당신이 누를 때 플레이어가 처음으로 전체 화면에서 촬영 한 다음 통지가 발생합니다 "완료"것으로 보인다. 문제를 해결할 것이다 removeFromSuperview 호출하기 전에

[_moviePlayer setFullscreen:NO animated:YES]; 

을 추가 this answer을 읽은 후. 위에서 작동하지 않으면 전체 코드가

-(void)removePlayer:(MPMoviePlayerController *)player{ 

    NSLog(@"Playback Finished"); 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayer]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer]; 

    [_moviePlayer stop]; // <-- May not be needed 
    if ([_moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) 
    { 
     [_moviePlayer setFullscreen:NO animated:YES]; 
     [_moviePlayer.view removeFromSuperview]; 

    } 

    _moviePlayer=nil; 



} 

내가 모두 알림 같은 방법을 사용할 수 있도록

는 추가로 먼저 선수를을 stoping하려고 할 수 있습니다 "완료"와 "PlayBackFinished"

희망이 도움이됩니다.

0

당신이보기로 _moviePlayer.view을 추가했다 당신은 내가이 그것을 할 것이라고 생각 player.view

을 제거하려고 :

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

MPMoviePlayerController *player = [notification object]; 

[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:player]; 

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

}

+0

여전히 똑같은 영화는 사라지지 않습니다. 이 픽스가 작동하기를 기대했지만 플레이어 = _moviePlayer에서 첫 번째 라인을 읽었을 때와 똑같은 것 같습니다. 문제는 마지막 줄에있는 것처럼 보입니다. – robertfiorentino