2

In the sample project, Guess the Intro, there is a method called waitAndFillTrackPool that gets all the tracks from a user's playlists. Inside this method, a call is made using SPAsyncLoading to get all the tracks' metadata.

 [SPAsyncLoading waitUntilLoaded:tracks timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedTracks, NSArray *notLoadedTracks) { 

   // All of our tracks have loaded their metadata. Hooray!
   NSLog(@"[%@ %@]: %@ of %@ tracks loaded.", NSStringFromClass([self class]), NSStringFromSelector(_cmd),[NSNumber numberWithInteger:loadedTracks.count], [NSNumber numberWithInteger:loadedTracks.count + notLoadedTracks.count]);

On success, as the comment says, the metadata for all tracks should be loaded. However, I am unable to get track.album.cover.image (it returns null). All other metadata seems to be there.

To test what is going on I added this after the metadata should be loaded:

 SPTrack *test = [theTrackPool objectAtIndex:0];
 NSLog(@"track: %@ , is loaded: %s, image loaded: %s",test.name,test.loaded ? "true" : "false", test.album.cover.loaded ? "true" : "false");

Which logs:

 track: Howlin' For You , is loaded: true, image loaded: false

If the metadata should be loaded, shouldn't the album cover also be available?

Just to clarify, I can get this particular track's album art if use the playback manager and key-value observing. However, I do experience the similar first value nil, second value correct as in Downloading cover art URL from Spotify and key-value observing. Maybe this is a similar bug? If the album art does need to be rechecked, how do I setup an observer to get the album art from an array of tracks?

Thanks for your time!

Community
  • 1
  • 1

1 Answers1

0

This is intended behaviour (imagine if we downloaded coverart for all tracks in a playlist at once when you load the playlist — it'd be an incredible amount of data!).

Accessing the image property will trigger the cover to be loaded, mainly for KVO. You can also use SPAsyncLoading to load them.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Thanks for the reply! That makes sense. If I wanted to load them via `SPAsyncLoading` how would I get an array of `SPImages`? I have tried to create a new class that loops over all the tracks and pulls out `track.album.cover` which doesn't work because it returns `nil`. Would I need to use `imageWithImageId:inSession:` using the libSpotify thread? – Siroberto Scerbo Jan 12 '13 at 20:56
  • No, use `SPAsyncLoading` on the array of tracks, then when they're loaded do [[tracks valueForKey:@"album"] valueForKey:@"cover"] to get the array of covers. – iKenndac Jan 12 '13 at 21:34
  • I tried two different approaches without success. The first is to iterate through the tracks and call `[aTrack.album.cover startLoading];` before loading them with `SPAsyncLoading`. I thought this would succeed with the album art loaded, then I could call your function to get the covers. It throws this error: 'NSInvalidArgumentException', reason: '-[NSNull isLoaded]' when checking `album.cover.loaded`. I also tried, after loading all the tracks, to get the album covers as you suggested and call `SPAsyncLoading` on the array of covers. This way has the same error when calling `SPAsyncloading`. – Siroberto Scerbo Jan 13 '13 at 23:45
  • Could you please provide some code or psuedo code to tell me the exact process of how I should be doing this? I have tried to loop over a few tracks and call `[cover startLoading]` to try and use KVO but the observer never gets notified of a change. Even waiting for over 20 min and manually checking the cover returns nil. Could there be something blocking the loading? Does `start loading` not work? Thanks for your help. – Siroberto Scerbo Jan 17 '13 at 18:50
  • `SPImage` isn't a complicated class at all — just take a look at its code for a better understanding of it. Also, see my answer to http://stackoverflow.com/questions/14287370/downloading-cover-art-url-from-spotify-and-key-value-observing/ – iKenndac Jan 18 '13 at 00:07