Fixed up metadata loading so metadata isn't always read when you play.

CQTexperiment
vspader 2009-03-05 20:46:42 -08:00
parent d6a0b0670e
commit 7cbebef352
4 changed files with 32 additions and 20 deletions

View File

@ -51,7 +51,10 @@
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe - (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe
{ {
[pe performSelectorOnMainThread:@selector(setValuesForKeysWithDictionary:) withObject:[playlistLoader readEntryInfo:pe] waitUntilDone:YES]; // Race here, but the worst that could happen is we re-read the data
if ([pe metadataLoaded] != YES) {
[pe performSelectorOnMainThread:@selector(setMetadata:) withObject:[playlistLoader readEntryInfo:pe] waitUntilDone:YES];
}
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) { if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
[scrobbler start:pe]; [scrobbler start:pe];

View File

@ -41,6 +41,8 @@
NSString *endian; NSString *endian;
BOOL seekable; BOOL seekable;
BOOL metadataLoaded;
} }
+ (NSSet *)keyPathsForValuesAffectingDisplay; + (NSSet *)keyPathsForValuesAffectingDisplay;
@ -91,4 +93,8 @@
@property BOOL seekable; @property BOOL seekable;
@property BOOL metadataLoaded;
- (void)setMetadata:(NSDictionary *)metadata;
@end @end

View File

@ -42,6 +42,8 @@
@synthesize seekable; @synthesize seekable;
@synthesize metadataLoaded;
// The following read-only keys depend on the values of other properties // The following read-only keys depend on the values of other properties
+ (NSSet *)keyPathsForValuesAffectingDisplay + (NSSet *)keyPathsForValuesAffectingDisplay
@ -182,4 +184,19 @@
return nil; return nil;
} }
- (void)setMetadata:(NSDictionary *)metadata
{
if (metadata == nil)
{
self.error = YES;
self.errorMessage = @"Unable to retrieve metadata.";
}
else
{
[self setValuesForKeysWithDictionary:metadata];
}
metadataLoaded = YES;
}
@end @end

View File

@ -334,24 +334,6 @@
return entryInfo; return entryInfo;
} }
- (void)processEntryInfo:(NSInvocationOperation *)operation
{
NSDictionary *entryInfo = [operation result];
PlaylistEntry *pe;
// get the playlist entry that the thread was inspecting
[[operation invocation] getArgument:&pe atIndex:2];
if (entryInfo == nil)
{
pe.error = YES;
pe.errorMessage = @"Unable to retrieve properties.";
}
else
{
[pe setValuesForKeysWithDictionary:entryInfo];
}
return;
}
- (void)observeValueForKeyPath:(NSString *)keyPath - (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object ofObject:(id)object
change:(NSDictionary *)change change:(NSDictionary *)change
@ -362,7 +344,11 @@
{ {
// stop observing // stop observing
[object removeObserver:self forKeyPath:keyPath]; [object removeObserver:self forKeyPath:keyPath];
[self performSelectorOnMainThread:@selector(processEntryInfo:) withObject:object waitUntilDone:NO];
// get the playlist entry that the operation read for
PlaylistEntry *pe = nil;
[[object invocation] getArgument:&pe atIndex:2];
[pe performSelectorOnMainThread:@selector(setMetadata:) withObject:[object result] waitUntilDone:NO];
} }
else else