2014-01-30 2 views
0

장치에서 노래를 재생할 때 다음 코드를 사용하고 있습니다. MPMusicPlayerController에 대한 알림을 추가하여 플레이어의 상태를 인식했습니다.왜 MPMusicPlayerController MPMusicPlayerControllerPlaybackStateDidChangeNotification이 두 번 호출 되었습니까?

self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer]; 
[self.musicPlayer beginGeneratingPlaybackNotifications]; 
[self.musicPlayer setRepeatMode: MPMusicRepeatModeNone]; 

뮤직 플레이어가 곡을 연주 할 때 다음과 같은 방법이 두 번 호출됩니다.

-(void)handlePlaybackStateChanged :(id)notification 

제 질문은 왜 두 번 부름 받았습니까? 어떤 도움을 주시면 감사하겠습니다.

+0

점검이 두 번 호출하고 알림을 기록하고이 호출 될 때 알아 내기 위해 중단 점을 추가하려고하지 않을에있는 기능입니다. – Jordan

답변

1

저는 지금 똑같은 문제를 해결하려고합니다. 여기 내가 찾은 것이있다. handlePlaybackStateChangedcurrentPlaybackRate이 0 (중지됨) 또는 1 (재생 중) 일 때 호출됩니다. nextSong 버튼을 누를 때 현재 노래를 멈추고 다음 노래를 재생하므로 두 번 발사됩니다. 아래 코드가 정리되어 있고 Swift에 있지만 내 요점을 알아야합니다.

func handle_PlaybackStateChanged(){ 
    println("handle_PlaybackStateChanged") 

    if player.currentPlaybackRate == 0{ 
     println("playbackStatePause0") 
    }else{ 
     println("playbackStatePause1") 
    } 
} 

노래 사이의 출력은

handle_PlaybackStateChanged 
playbackStatePause0 
handle_PlaybackStateChanged 
playbackStatePause1 
관련 문제