2010-04-14 59 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

相关问题