Bai*_*ose 3 iphone sdk cocoa-touch itunes
是否有任何适用于iPhone OS的iTunes API,我可以使用它从iTunes访问某些信息(当前曲目等)?
我环顾四周,但我能找到的只是一些AppleScript和COM API.
您需要在Xcode和#import MediaPlayer/MediaPlayer.h中将MediaPlayer.framework添加到目标
然后
就像是
@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
...
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
Run Code Online (Sandbox Code Playgroud)
然后在viewDidLoad中,您需要注册该事件
// Register for music player notifications
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(handleNowPlayingItemChanged:)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:self.musicPlayer];
Run Code Online (Sandbox Code Playgroud)
现在实现handleNowPlayingItemChanged
当正在播放的项目发生变化时,您将通过调用此方法获得通知
- (void)handleNowPlayingItemChanged:(id)notification {
// Ask the music player for the current song.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1022 次 |
| 最近记录: |