2012-10-08 9 views
10

私のタイトルに非常によく似ているかもしれませんが、NSNotificationがムービーの再生を終了したとは限りません。私はこの問題を持つ他の人たちを見つけましたが、ソリューションはありません、私が実行しているものであるiOS 6の問題かもしれないようです。MPMoviePlayerControllerは、再生終了後にムービーを自動的に解除しません。(ios 6)

動画の再生が終了したら、[完了]を押すと終了しますが、一度削除するとMPMovieControlStyleNoneを使用するため、自動的に終了します。ここで取り除か未使用セクションとの私のコードは次のとおりです。 `

#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` 

答えて

18

は、ちょうど最後に

スーパー
+0

からビューを削除する前に

を追加moviePlayBackDidFinish に固定するために、この問題にも を持っていた、A溶液!これは完璧に働いた、ありがとう。 – robertfiorentino

+0

優秀回答です。アップ票です。 –

+2

逆にする必要があります。私はMPMoviePlayerControllerが自動的に却下しないようにしたい。ユーザーは、* Done *ボタンを使用してそれを却下することができます –

関連する問題