4

我想从一个MP3文件的专辑封面获取专辑插图。从MP3文件/ ID3标签

在这种情况下,我使用AVAudioPlayer播放文件。

下面的代码,我认为会得到专辑封面:

MPMusicPlayerController *controller = [MPMusicPlayerController applicationMusicPlayer]; 

MPMediaItem *current = controller.nowPlayingItem; 

MPMediaItemArtwork *artwork = [current valueForProperty:MPMediaItemPropertyArtwork]; 
UIImage *artwork2 = [artwork imageWithSize:artwork.bounds.size]; 
[artworkView setImage:artwork2]; 

然而artworkView不包含任何图片任何责任。

我有点卡住了。

如果任何一个可以通过提供建议的地方/我怎样才能从ID3标签,这将是非常有用直接将艺术品帮助。

任何帮助表示赞赏。

回答

4

你必须在这里使用enumerateValuesForProperties是一个示例:

[item enumerateValuesForProperties:[NSSet setWithObjects:MPMediaItemPropertyTitle,MPMediaItemPropertyAlbumTitle,MPMediaItemPropertyArtist,MPMediaItemPropertyArtwork,nil] 
           usingBlock:^(NSString *property, id value, BOOL *stop) { 
            if ([property isEqualToString:MPMediaItemPropertyTitle]){ 
             if (value){ 
              titre=value; 
             }else { 
              [email protected]""; 
             } 
            } 
            if ([property isEqualToString:MPMediaItemPropertyArtist]){ 
             if(value){ 
              artist=value; 
             }else { 
              [email protected]""; 
             } 

            } 
            if ([property isEqualToString:MPMediaItemPropertyArtwork]){ 
             MPMediaItemArtwork *art=value; 
             if (art!=nil){ 
              imgV.image=[art imageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.width)]; 
            } 

            } 


           }];