我想从iPod Music中获取iPod音乐的名称和艺术家名称但是我想要当音乐更改时,我可以检测到uilabel的变化
这是代码:
- (IBAction)getTitlemusic
{
// MPMediaItem * currentItem = self.musicPlayer.nowPlayingItem;
MPMediaItem * song = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
NSString * album = [song valueForProperty:MPMediaItemPropertyAlbumTitle];
NSString * title = [song valueForProperty:MPMediaItemPropertyTitle];
NSString * artist = [song valueForProperty:MPMediaItemPropertyArtist];
NSLog(@"%@,%@,%@", album,title,artist);
songlabel.text = [NSString stringWithFormat:@"%@",album ];
arttistlabel.text = [NSString stringWithFormat:@"%@r%@",title,artist];
[self performSelector:@selector(getTitlemusic) withObject:nil afterDelay:10.0f];
}
我知道计时器和延迟不是很好的主意
MPMusicPlayerController *player = [MPMusicPlayerController iPodMusicPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getTitlemusic)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:player];
[player beginGeneratingPlaybackNotifications];
使用此代码