获取MP3和M4A音乐文件的歌曲信息以及专辑图片--备用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取MP3和M4A音乐文件的歌曲信息以及专辑图片--备用相关的知识,希望对你有一定的参考价值。
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle bundlePath];
NSURL * fileURL=[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/akon、be - you - with.mp3", path]];
AudioFileTypeID fileTypeHint = kAudioFileMP3Type;
NSString *fileExtension = [[fileURL path] pathExtension];
if ([fileExtension isEqual:@"mp3"]||[fileExtension isEqual:@"m4a"])
{
AudioFileID fileID = nil;
OSStatus err = noErr;
err = AudioFileOpenURL( (CFURLRef) fileURL, kAudioFileReadPermission, 0, &fileID );
if( err != noErr ) {
NSLog( @"AudioFileOpenURL failed" );
}
UInt32 id3DataSize = 0;
err = AudioFileGetPropertyInfo( fileID, kAudioFilePropertyID3Tag, &id3DataSize, NULL );
if( err != noErr ) {
NSLog( @"AudioFileGetPropertyInfo failed for ID3 tag" );
}
NSDictionary *piDict = nil;
UInt32 piDataSize = sizeof( piDict );
err = AudioFileGetProperty( fileID, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict );
if( err != noErr ) {
[piDict release];
NSLog( @"AudioFileGetProperty failed for property info dictionary" );
}
CFDataRef AlbumPic= nil;
UInt32 picDataSize = sizeof(picDataSize);
err =AudioFileGetProperty( fileID, kAudioFilePropertyAlbumArtwork, &picDataSize, &AlbumPic);
if( err != noErr ) {
NSLog( @"Get picture failed" );
}
NSData* imagedata= (NSData*)AlbumPic;
UIImage* image=[[UIImage alloc]initWithData:imagedata];
imageView.image=image;
NSString * Album = [(NSDictionary*)piDict objectForKey:
[NSString stringWithUTF8String: kAFInfoDictionary_Album]];
NSString * Artist = [(NSDictionary*)piDict objectForKey:
[NSString stringWithUTF8String: kAFInfoDictionary_Artist]];
NSString * Title = [(NSDictionary*)piDict objectForKey:
[NSString stringWithUTF8String: kAFInfoDictionary_Title]];
NSLog(@"%@",Title);
NSLog(@"%@",Artist);
NSLog(@"%@",Album);
}
以上是关于获取MP3和M4A音乐文件的歌曲信息以及专辑图片--备用的主要内容,如果未能解决你的问题,请参考以下文章