2011-08-02 7 views
0

私はオーディオベースのアプリケーションを実装しています。その中で私は2つのAVPlayersを使って2つの異なるサウンドを演奏しています。私はいったん演奏されたら、別の行動をする必要があります。このため私はNSNotificationsを使用しました。しかし、私の問題は、どのプレイヤーに関連する通知を見つけることができないということです。私の通知コードとセレクターコードは次の通りです。予めNSNotificationCenter with arguments

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playingItemDidEnd:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:iPodPlayer]; 


[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playingItemDidEnd:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:applicationPlayer ]; 

- (void)playingItemDidEnd:(NSNotification *)notification 
{ 
     id object= [notification object]; 

    if(object==ipodPlayer) 
    { 
     printf("\n Notification from iPod Player "); 

    } 
    else if(object==applicationPlayer) 
    { 
     printf("\n Notification from application Player "); 
    } 

}

おかげで、 チャンドラ。

答えて

3

Iは

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

    AVPlayerItem* object= [notification object]; 
    if(object==[applicationPlayer currentItem]) 
    { 

    } 
    else if(object==[avPlayer currentItem]) 
    { 

    } 
} 
、以下のようでなければならない

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playingItemDidEnd:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:[applicationPlayer currentItem] ]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playingItemDidEnd:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:[iPodPlayer currentItem]]; 

セレクタコード、次のようにコードベースを変更する必要が

関連する問題