在iPhone上:找出目前正在播放的歌曲? (在iPod音乐播放器中)

问题描述:

Apple发布了访问iPod库在iPhone SDK 3.0中,我想知道现在是否可以理解当前正在播放哪首歌?标题,艺术家,专辑就足够了。示例:用户打开应用程序,应用程序可以知道后台正在播放哪首歌。

Apple released access to the iPod Library in the iPhone SDK 3.0 and I'm wondering if it's now possible to understand which song is currently playing? Title, Artist, Album suffices. Example: User opens an app and the app can know which song is playing in the background.

有没有人有这方面的经验?

Has anyone had any experience with this?

非常感谢!

MPMediaItem * song = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
NSString * title   = [song valueForProperty:MPMediaItemPropertyTitle];
NSString * album   = [song valueForProperty:MPMediaItemPropertyAlbumTitle];
NSString * artist  = [song valueForProperty:MPMediaItemPropertyArtist];