diff --git a/Application/PlaybackEventController.m b/Application/PlaybackEventController.m index 5d41e564c..ad77e6fab 100644 --- a/Application/PlaybackEventController.m +++ b/Application/PlaybackEventController.m @@ -51,7 +51,10 @@ - (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"]) { [scrobbler start:pe]; diff --git a/Playlist/PlaylistEntry.h b/Playlist/PlaylistEntry.h index fe511beae..4b9fb6d46 100644 --- a/Playlist/PlaylistEntry.h +++ b/Playlist/PlaylistEntry.h @@ -41,6 +41,8 @@ NSString *endian; BOOL seekable; + + BOOL metadataLoaded; } + (NSSet *)keyPathsForValuesAffectingDisplay; @@ -91,4 +93,8 @@ @property BOOL seekable; +@property BOOL metadataLoaded; + +- (void)setMetadata:(NSDictionary *)metadata; + @end diff --git a/Playlist/PlaylistEntry.m b/Playlist/PlaylistEntry.m index 0a96a7480..f9c3b42bf 100644 --- a/Playlist/PlaylistEntry.m +++ b/Playlist/PlaylistEntry.m @@ -42,6 +42,8 @@ @synthesize seekable; +@synthesize metadataLoaded; + // The following read-only keys depend on the values of other properties + (NSSet *)keyPathsForValuesAffectingDisplay @@ -182,4 +184,19 @@ 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 diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index cdce75a9c..f965fd364 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -334,24 +334,6 @@ 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 ofObject:(id)object change:(NSDictionary *)change @@ -362,7 +344,11 @@ { // stop observing [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