From e531f288b261055bdd938f52568dafb0b46e1e24 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Sat, 7 May 2016 22:41:28 -0700 Subject: [PATCH] Fix a race condition with opening files externally through file associations or the 'open' terminal command. --- Application/PlaybackController.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index 17df92a23..4e5d3469e 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -159,10 +159,18 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) if (pe == nil) return; +#if 0 // Race here, but the worst that could happen is we re-read the data - if ([pe metadataLoaded] != YES) { + if ([pe metadataLoaded] != YES) { [pe performSelectorOnMainThread:@selector(setMetadata:) withObject:[playlistLoader readEntryInfo:pe] waitUntilDone:YES]; } +#else + // Racing with this version is less likely to jam up the main thread + if ([pe metadataLoaded] != YES) { + NSArray * entries = [NSArray arrayWithObject:pe]; + [playlistLoader loadInfoForEntries:entries]; + } +#endif [audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused]; } @@ -479,7 +487,8 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) { pe = [playlistController getNextEntry:curEntry]; if (pe && [pe metadataLoaded] != YES) { - [pe performSelectorOnMainThread:@selector(setMetadata:) withObject:[playlistLoader readEntryInfo:pe] waitUntilDone:YES]; + NSArray * entries = [NSArray arrayWithObject:pe]; + [playlistLoader loadInfoForEntries:entries]; } }