如何从ipod库歌曲中获取歌词

时间:2011-08-03 08:11:48

标签: iphone ipod mpmediaitem

我在iphone应用程序中访问ipod库并显示专辑的标题,歌词和艺术作品。我还想显示歌曲的歌词。我在iTunes中添加了歌词并将其与设备同步。但我的代码没有显示歌词..

Example from here以及获取歌词的代码是: -

- (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:MPMediaItemPropertyAlbumArtist];
    self.albumLabel.text  = [[currentItem valueForProperty:MPMediaItemPropertyLyrics]retain];    


}

请帮助。感谢

1 个答案:

答案 0 :(得分:1)

NSURL* songURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL] 
AVAsset* songAsset = [AVURLAsset URLAssetWithURL:songURL options:nil]; 
NSString* lyrics = [songAsset lyrics];