I'd like to quickly get a list of artist names in a user's "library" or playlists. Is there an easy / asynchronous way to do this?
Asked
Active
Viewed 706 times
1 Answers
5
Take a look at the example project "Guess the Intro" included with CocoaLibSpotify. The method waitAndFillTrackPool
in that project shows how to get a list of all the tracks in the user's playlists.
Once you have that list, you can do the following to get the artists from them, put them through a set to thin out duplicates, then wait until they're loaded.
NSArray *artists = [theTrackPool valueForKeyPath:@"@unionOfArrays.artists"];
NSArray *uniqueArtists = [[NSSet setWithArray:artists] allObjects];
[SPAsyncLoading waitUntilLoaded:uniqueArtists then:^(NSArray *loadedArtists) {
// Artists are loaded!
// Log a list of artist names...
NSLog(@"%@", [loadedArtists valueForKey:@"name"]);
}];
![](../../users/profiles/29005.webp)
iKenndac
- 18,537
- 3
- 32
- 50
-
I'm noticing in the guess the intro app and when I implement it myself that the initial 'then' block returns only 2 playlists (and 5 tracks). When I close the app and reopen it, the second time around waitAndFillTrackPool gives all 6 playlist and a lot more tracks. Any reason? – devinross May 24 '12 at 06:43
-
Can I get all tracks when using SPAsyncLoading the first time? – devinross May 24 '12 at 06:46
-
Yes - read the documentation to [SPAsyncLoading waitUntilLoaded:timeout:then:]. You need to increase the timeout. – iKenndac May 24 '12 at 07:56