MPMoviePlayerController当前播放的项目详情?

时间:2012-04-12 06:25:38

标签: iphone mpmovieplayercontroller currentitem

我正在使用MPMoviePlayerController播放音频流网址,它工作正常,是他们以任何方式获取当前播放曲目的详细信息..我的意思是歌曲标题,艺术家姓名等。

提前致谢

2 个答案:

答案 0 :(得分:2)

添加此.h文件

@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)

MPMoviePlayerController不支持从播放的流中获取基于ID3的元数据。您必须使用MPMusicPlayerController(本地内容)或可能AVPlayer(流内容)才能完成该任务。虽然我必须承认,我并不完全确定AVPlayer / AVPlayerItem是否能真正完成工作 - 我自己从未尝试过。