Re: get iTunes songs
Re: get iTunes songs
- Subject: Re: get iTunes songs
- From: Matt Neuburg <email@hidden>
- Date: Mon, 16 Oct 2006 11:55:10 -0700
- Thread-topic: get iTunes songs
On Mon, 16 Oct 2006 17:16:26 +0300, Olariu Adrian Mihai <email@hidden>
said:
>If I have about 5000 tracks in the library mand it takes about 20
>seconds to load all the track in my table view. Below is the code that I
>use to load tracks.
>
> while (track = [trackEnum nextObject])
> {
>
> id obj=[trackArray objectAtIndex:count];
> count++;
> if ([track databaseId] == [currentTrack databaseId])
> {
> currentTrackObject = obj;
> [obj setValue:[playIcon image] forKey:@"Status"];
> }
> NSString *artist = [track artist];
> [obj setValue:track forKey:@"Track"];
> [obj setValue:[track name] forKey:@"Name"];
> [obj setValue:[track time] forKey:@"Time"];
> [obj setValue:artist forKey:@"Artist"];
> [obj setValue:[track album] forKey:@"Album"];
> [obj setValue:[[NSNumber alloc] initWithInt:[track rating]/20 ]
>forKey:@"MyRating"];
>
> if (![artist isEqualToString:@""])
> if (![artistArray containsObject:artist])
> [artistArray addObject:artist];
> }
>
This construct is lightning-fast OMM:
tell application "iTunes"
tell library playlist "Library"
get {name, time, album, artist} of every track
end tell
end tell
Try that, modifying as necessary. The reason is that you aren't cycling thru
every track (iTunes is) and you're only sending one Apple event. My
AppleScript book gives this and other similar tips about speed. Of course
you don't have to use AppleScript; you could use the raw Apple event version
of that same code. But when it's a matter of sending just one Apple event,
there's really no appreciable gain in that approach (especially if you
pre-compile the script). m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
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