2011-08-02 6 views
0

を放出することができない私は、グローバル変数を作成しました)videoType {はMPMoviePlayerController

ViewVideoSubview.alpha = 0; 

NSString *url = [[NSBundle mainBundle] 
       pathForResource:videoName 
       ofType:videoType]; 


player = 
[[MPMoviePlayerController alloc] 
initWithContentURL:[NSURL fileURLWithPath:url]]; 


player.shouldAutoplay =YES; 



[ViewVideoSubview addSubview:player.view]; 



[[NSNotificationCenter defaultCenter] 
addObserver:self 
selector:@selector(movieFinishedCallback:)             
name:MPMoviePlayerPlaybackDidFinishNotification 
object:player]; 

}

及びビデオplayiを終了したときそれ自体では、以下の呼び出しメソッドが呼び出されます。

- (void) movieFinishedCallback:(NSNotification*) aNotification { 



    [player.view removeFromSuperview]; //d1 
    MPMoviePlayerController *playerParam = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:playerParam]; 

    [player release]; 

} 

これまでのところすべて素晴らしいです。問題は、押されたときに別のView Controllerをロードする必要があるボタンがあることです。私はそのビューコントローラをロードすることができますが、ビデオはまだバックグラウンドで再生されます。なぜ私はプレーヤーを解放するときにエラーが発生しないのですか?私の一時的な解決策は、ビデオを停止し、ビデオがバックグラウンドで再生されないように他のView Controllerをロードすることです。

私が考えていたもう一つの解決策は、movieFinishedCallbackメソッドで解放されるように、ビデオが再生を終了する1秒前に再生することです。ビデオをその時点まで「早送り」する方法がわからない。私はobjective-cが新しく、aNotificationパラメータが何か分からない場合は、適切なパラメータでそのメソッドを呼び出すだけです。

enter image description here enter image description here

答えて

2

は、私が思うあなたの問題はあなたがmovieFinishedCallback

ここの方法で観測者を削除しようとしている方法である:

私はあなたに私が取得していますエラーを表示してみましょうグローバルプロパティプレイヤーにポインターを渡しています。

MPMoviePlayerController *playerParam = [aNotification object]; 

、ここではあなたがあなたのplayerへのポインタ(playerParam)を送信しているためplayerParam

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

は今、あなたはすでに(EXEC_BAD_ACCESSを取得し、このオブジェクトに関するすべての通知のオブザーバを削除する方法をinvocingています(removeObserver)に転送して、存在しないオブジェクトに対してremoveObserverというオペレーションを呼び出すことができます。名前notificationObserver(ID):(NSStringの * - (無効)removeObserverを

代わりの

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

を使用すると、あなたのオブジェクトnilをします作る

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

を試してみてください)notificationNameオブジェクト:(id)notificationSender

通知送信者... nilの場合、受信者は通知の送信者を条件として削除します( )。詳細情報は、NSNotificationCenter Class Reference

で見つけることができ

関連する問題