14. Add Album Art to mp3 files in iOS

Prerequisite: Download ID3 C Library from here – http://sourceforge.net/projects/id3lib/files/id3lib/3.8.3/id3lib-3.8.3.zip/download

And use below method to add album art in the given mp3 file:

-#import <id3/tag.h>//update the Header Search path with the location of this library under your project

-(void)addMetaDataToMP3File:(NSString*)songFilePath withAlbumArtFile:(NSString*)artworkImgPath

{

    

    ID3_Tag tag;

    tag.Link([songFilePath UTF8String]);

    tag.Strip(ID3TT_ALL);

    tag.Clear();

    ID3_Frame frame;

    frame.SetID(ID3FID_PICTURE);

    frame.GetField(ID3FN_MIMETYPE)->Set((constchar *)[@"image/jpeg"cStringUsingEncoding:NSUTF8StringEncoding]);

    frame.GetField(ID3FN_PICTURETYPE)->Set(ID3PT_COVERFRONT);

    frame.GetField(ID3FN_DATA)->FromFile((constchar *)[artworkImgPath cStringUsingEncoding:NSUTF8StringEncoding]);

    tag.AddFrame(frame);

    tag.SetPadding(false);

    tag.SetUnsync(false);

    tag.Update(ID3TT_ID3V2);

}

 

Leave a Reply