我是否可以使用iPhone OS的iTunes API从iTunes获取某些信息(当前曲目等)?
我环顾四周,但我能找到的只是一些AppleScript和COM API。
答案 0 :(得分:6)
您需要在Xcode和#import MediaPlayer / MediaPlayer.h中将MediaPlayer.framework添加到目标
然后
类似
@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];
实现handleNowPlayingItemChanged 现在
当正在播放的项目发生变化时,您将通过调用此方法来通知
- (void)handleNowPlayingItemChanged:(id)notification {
// Ask the music player for the current song.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;