2010-04-14 27 views

回答

6

您需要MediaPlayer.framework添加到您的目標在Xcode和#進口的MediaPlayer/MediaPlayer.h

然後

@property (nonatomic, retain) MPMusicPlayerController *musicPlayer; 
... 
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; 

然後在viewDidLoad中,你需要爲登記事件

// Register for music player notifications 
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 
[notificationCenter addObserver:self 
         selector:@selector(handleNowPlayingItemChanged:) 
          name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification 
         object:self.musicPlayer]; 

implements handleNowPlayingItem改變 現在

當正在播放的項目改變了你的無線本地環路獲取調用此方法

- (void)handleNowPlayingItemChanged:(id)notification { 
    // Ask the music player for the current song. 
    MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem; 
+0

非常感謝米希爾通知! – 2010-04-14 10:56:06

相關問題