• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing MP3 and AAC album art
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing MP3 and AAC album art


  • Subject: Re: Accessing MP3 and AAC album art
  • From: Mark Knopper <email@hidden>
  • Date: Wed, 18 May 2005 22:38:50 -0400

On May 17, 2005, at 1:04 AM, Michael Jurewitz wrote:

I was wondering if anyone has any experience with programmatically accessing and setting album art from MP3 and AAC files. I've seen album art accessed using AppleScript, but I'm rather interested in how to do it using Cocoa (and any related SDK).


I looked into this for a while and finally decided to use Applescript to tell iTunes to give me the album art. Here is the code (feel free to use for any application).


// The script returns a two-item list {artworkData, artworkFormat}.
// The data contains a spurious 222 byte header followed by the raw JPEG, PNG etc. data.
// The format is a string that could be "JPEG" or "PNG".


        NSAppleScript *getArtScript;
        NSAppleEventDescriptor *descriptor;
        NSString *searchString, *pictureFormat;
        NSData *pictureData, *pictureDataWithoutHeader;
        NSRange pictureRange;
        int picture_length;
        NSImage *pictureImage;
        NSDictionary *errorInfo;

getArtScript = [[NSAppleScript alloc] initWithSource:
[NSString stringWithFormat:
@"with timeout of 5 seconds \n \
tell application \"iTunes \" \n \
set these_tracks to (search playlist \"Library\" for \"%@\") \n \
set theTrack to item 1 of these_tracks \n \
set artworkData to (data of artwork 1 of theTrack) as picture \n \
set artworkFormat to (format of artwork 1 of theTrack) as string \n \
return (artworkData, artworkFormat) \n \
end tell \n \
end timeout",searchString]];


        descriptor = [getArtScript executeAndReturnError:&errorInfo];

        if (descriptor==nil) {
            NSLog([errorInfo description]);
            return; // not much point going on from here.
        }
        pictureFormat = [[descriptor descriptorAtIndex:2] stringValue];
        pictureData = [[descriptor descriptorAtIndex:1] data];
        picture_length = [pictureData length];

// leave out the first 222 bytes.
pictureRange = NSMakeRange(222, (picture_length-222));
pictureDataWithoutHeader = [pictureData subdataWithRange:pictureRange];


pictureImage = [[[NSImage alloc] initWithData:pictureDataWithoutHeader] autorelease]; // finally got an NSImage.
[imageIBOutlet setImage:pictureImage];


        [getArtScript release];


I did find a few open source programs (eg. libid3tag) that would pick out the album art from MP3 files, but nothing for AAC or other formats unfortunately. Ideally there would be a cocoa framework for this...


        Mark



On May 17, 2005, at 1:04 AM, Michael Jurewitz wrote:


I was wondering if anyone has any experience with programmatically accessing and setting album art from MP3 and AAC files. I've seen album art accessed using AppleScript, but I'm rather interested in how to do it using Cocoa (and any related SDK).

Many thanks in advance!

-Michael Jurewitz

*********************************************
Northwestern University

2341 Sheridan Road
Evanston, IL
60201

Room:  847-332-9515
Cell:  909-717-5474
*********************************************



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Accessing MP3 and AAC album art
      • From: "J.M.Brough" <email@hidden>
References: 
 >Accessing MP3 and AAC album art (From: Michael Jurewitz <email@hidden>)

  • Prev by Date: NSControllerObjectProxy
  • Next by Date: Re: Using an alternate sort selector for a bound table column?
  • Previous by thread: Accessing MP3 and AAC album art
  • Next by thread: Re: Accessing MP3 and AAC album art
  • Index(es):
    • Date
    • Thread