2011-08-02 2 views
0

오디오 기반 응용 프로그램을 구현 중입니다. 그 점에서 저는 두 개의 AVPlayers를 사용하여 두 가지 다른 사운드를 재생하고 있습니다. 나는 일단 소리가 연주되면 다른 행동을 취할 필요가있다. 이를 위해 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 "); 
    } 

} 사전에

감사합니다, 찬드라. 다음과 같이

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

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

그리고 선택 코드가 있어야합니다 나는 다음과 같은 코드베이스를 변경해야

답변

3

,

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

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

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

    } 
}