Get song information and album images for MP3 and m4a music files-Alternate

Source: Internet
Author: User
Tags id3 tag

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

}

Get song information and album images for MP3 and m4a music files-Alternate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.