Convert playlist metadata loader to use code blocks, which fixes references and stops crashes on adding new tracks.
This commit is contained in:
parent
f0bee5ea6c
commit
ba9fe0534f
1 changed files with 17 additions and 53 deletions
|
@ -456,20 +456,24 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
for (PlaylistEntry *pe in entries)
|
for (PlaylistEntry *pe in entries)
|
||||||
{
|
{
|
||||||
if ([pe metadataLoaded]) continue;
|
if ([pe metadataLoaded]) continue;
|
||||||
|
|
||||||
|
__block PlaylistEntry *weakPe = pe;
|
||||||
|
__block NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:20];
|
||||||
|
|
||||||
@autoreleasepool {
|
NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
NSInvocationOperation *readEntryInfoOperation;
|
NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:weakPe.URL];
|
||||||
readEntryInfoOperation = [[NSInvocationOperation alloc]
|
if (entryProperties == nil)
|
||||||
initWithTarget:self
|
return;
|
||||||
selector:@selector(readEntryInfo:)
|
|
||||||
object:pe];
|
[entryInfo addEntriesFromDictionary:entryProperties];
|
||||||
|
[entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:weakPe.URL]];
|
||||||
[readEntryInfoOperation addObserver:self
|
}];
|
||||||
forKeyPath:@"isFinished"
|
|
||||||
options:NSKeyValueObservingOptionNew
|
[op setCompletionBlock:^{
|
||||||
context:NULL];
|
[weakPe performSelectorOnMainThread:@selector(setMetadata:) withObject:entryInfo waitUntilDone:NO];
|
||||||
[queue addOperation:readEntryInfoOperation];
|
}];
|
||||||
}
|
|
||||||
|
[queue addOperation:op];
|
||||||
}
|
}
|
||||||
|
|
||||||
[queue waitUntilAllOperationsAreFinished];
|
[queue waitUntilAllOperationsAreFinished];
|
||||||
|
@ -477,46 +481,6 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
[playlistController performSelectorOnMainThread:@selector(updateTotalTime) withObject:nil waitUntilDone:NO];
|
[playlistController performSelectorOnMainThread:@selector(updateTotalTime) withObject:nil waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)readEntryInfo:(PlaylistEntry *)pe
|
|
||||||
{
|
|
||||||
// Just setting this to 20 for now...
|
|
||||||
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:20];
|
|
||||||
NSDictionary *entryProperties;
|
|
||||||
entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL];
|
|
||||||
if (entryProperties == nil)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
[entryInfo addEntriesFromDictionary:entryProperties];
|
|
||||||
[entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]];
|
|
||||||
return entryInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
||||||
ofObject:(id)object
|
|
||||||
change:(NSDictionary *)change
|
|
||||||
context:(void *)context
|
|
||||||
{
|
|
||||||
// We finished reading the info for a playlist entry
|
|
||||||
if ([keyPath isEqualToString:@"isFinished"] && [object isFinished])
|
|
||||||
{
|
|
||||||
// stop observing
|
|
||||||
[object removeObserver:self forKeyPath:keyPath];
|
|
||||||
|
|
||||||
// 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
|
|
||||||
{
|
|
||||||
[super observeValueForKeyPath:keyPath
|
|
||||||
ofObject:object
|
|
||||||
change:change
|
|
||||||
context:context];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)clear:(id)sender
|
- (void)clear:(id)sender
|
||||||
{
|
{
|
||||||
[playlistController clear:sender];
|
[playlistController clear:sender];
|
||||||
|
|
Loading…
Reference in a new issue