iOS,当音乐改变时读取标题音乐ipod
Posted
技术标签:
【中文标题】iOS,当音乐改变时读取标题音乐ipod【英文标题】:iOS , read title music ipod when the music is change 【发布时间】:2014-01-29 19:25:44 【问题描述】:我想从当前正在播放的 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];
我知道计时器和延迟不是个好主意
【问题讨论】:
【参考方案1】:MPMusicPlayerController *player = [MPMusicPlayerController iPodMusicPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getTitlemusic)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:player];
[player beginGeneratingPlaybackNotifications];
使用此代码
【讨论】:
以上是关于iOS,当音乐改变时读取标题音乐ipod的主要内容,如果未能解决你的问题,请参考以下文章
iOS:降低包含 iPod 音乐的 MPMediaItem 的比特率
IOS iPhone使用MPMusicPlayerController播放外部音乐文件,显示iPod界面