如何在ios应用程序中的MPMusicPlayerController中获取当前播放歌曲数据

时间:2013-06-06 12:13:38

标签: ios objective-c mpmusicplayercontroller

我正在处理在MPMusicPlayerController中播放的歌曲,现在我想获取当前播放歌曲数据(例如:some.mp3)

请提前帮助我

2 个答案:

答案 0 :(得分:2)

尝试这个

@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
@property (nonatomic, retain) IBOutlet UILabel *songLabel;
@property (nonatomic, retain) IBOutlet UILabel *artistLabel;
@property (nonatomic, retain) IBOutlet UILabel *albumLabel;


- (void)handleNowPlayingItemChanged:(id)notification 
{
// Ask the music player for the current song.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;

// Display the artist, album, and song name for the now-playing media item.
// These are all UILabels.
 self.songLabel.text   = [currentItem valueForProperty:MPMediaItemPropertyTitle];
 self.artistLabel.text = [currentItem valueForProperty:MPMediaItemPropertyArtist];
 self.albumLabel.text  = [currentItem valueForProperty:MPMediaItemPropertyAlbumTitle];    
 // Display album artwork. self.artworkImageView is a UIImageView.
 CGSize artworkImageViewSize = self.artworkImageView.bounds.size;
 MPMediaItemArtwork *artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
 if (artwork != nil) 
 {
      self.artworkImageView.image = [artwork imageWithSize:artworkImageViewSize];
 }   
else
{
        self.artworkImageView.image = nil;
}
}

答案 1 :(得分:1)

您可以向MPMusicPlayerController询问当前正在播放的歌曲

MPMediaItem  *songItem = [controller nowPlayingItem];

然后提取文件(如在mp3中)有2 options。看看前2个答案。