2010-10-26 63 views

回答

5

註冊MPMusicPlayerControllerPlaybackStateDidChangeNotification通知:

[notificationCenter addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer]; 

,並告訴你musicPlayerController產生這些通知:

[self.musicPlayerController beginGeneratingPlaybackNotifications]; 

handlePlaybackStateChanged:您可以檢查musicPlayerController的playbackState屬性:

- (void)handlePlaybackStateChanged:(NSNotitication*)notification 
{ 
    if (self.musicPlayerController.playbackState == MPMusicPlaybackStateStopped || 
     self.musicPlayerController.playbackState == MPMusicPlaybackStateInterrupted || 
     self.musicPlayerController.playbackState == MPMusicPlaybackStatePaused) { 
     // do your stuff 
    } 
} 
相關問題