Fixed major spotlight bug by retaining static key array (duh). Spotlight doesn't crash anymore and works very quickly.

CQTexperiment
matthewleon 2008-02-12 11:11:26 +00:00
parent a5c8447b8d
commit 7c2d290871
1 changed files with 13 additions and 11 deletions

View File

@ -27,28 +27,28 @@ static NSDictionary * tags;
+ (void)initialize + (void)initialize
{ {
mdKeys = [NSArray arrayWithObjects: mdKeys = [[NSArray arrayWithObjects:
@"kMDItemTitle", @"kMDItemTitle",
@"kMDItemAlbum", @"kMDItemAlbum",
@"kMDItemAudioTrackNumber", @"kMDItemAudioTrackNumber",
@"kMDItemRecordingYear", @"kMDItemRecordingYear",
@"kMDItemMusicalGenre", @"kMDItemMusicalGenre",
@"kMDItemDurationSeconds", @"kMDItemDurationSeconds",
nil]; nil] retain];
entryKeys = [NSArray arrayWithObjects: entryKeys = [[NSArray arrayWithObjects:
@"title", @"title",
@"album", @"album",
@"track", @"track",
@"year", @"year",
@"genre", @"genre",
@"length", @"length",
nil]; nil]retain];
extramdKeys = [NSArray arrayWithObjects: extramdKeys = [[NSArray arrayWithObjects:
@"kMDItemPath", // @"kMDItemPath",
@"kMDItemAuthors", @"kMDItemAuthors",
nil]; nil]retain];
allmdKeys = [mdKeys arrayByAddingObjectsFromArray:extramdKeys]; allmdKeys = [[mdKeys arrayByAddingObjectsFromArray:extramdKeys]retain];
tags = [NSDictionary dictionaryWithObjects:entryKeys forKeys:mdKeys]; tags = [[NSDictionary dictionaryWithObjects:entryKeys forKeys:mdKeys]retain];
} }
// Use this to access the array of all the keys we want. // Use this to access the array of all the keys we want.
@ -61,6 +61,7 @@ static NSDictionary * tags;
{ {
// use the matching tag sets to generate a playlist entry // use the matching tag sets to generate a playlist entry
SpotlightPlaylistEntry *entry = [[[SpotlightPlaylistEntry alloc] init] autorelease]; SpotlightPlaylistEntry *entry = [[[SpotlightPlaylistEntry alloc] init] autorelease];
NSDictionary *songAttributes = [metadataItem valuesForAttributes:allmdKeys]; NSDictionary *songAttributes = [metadataItem valuesForAttributes:allmdKeys];
for (NSString * mdKey in tags) { for (NSString * mdKey in tags) {
[entry setValue: [songAttributes objectForKey:mdKey] [entry setValue: [songAttributes objectForKey:mdKey]
@ -68,7 +69,8 @@ static NSDictionary * tags;
} }
// URL needs to be generated from the simple path stored in kMDItemPath // URL needs to be generated from the simple path stored in kMDItemPath
[entry setURL: [NSURL fileURLWithPath: [songAttributes objectForKey:@"kMDItemPath"]]]; // Will deal with this complication later.
// [entry setURL: [NSURL fileURLWithPath: [songAttributes objectForKey:@"kMDItemPath"]]];
// Authors is an array, but we only care about the first item in it // Authors is an array, but we only care about the first item in it