0

I have issues with loading playlists using the SPAsyncLoading class. Sometimes the call does not return at all, sometimes after a long time.

I use the following code to load a playlist from a url:

NSString *playlistUrl = [Config instance].playlistUrl;
[SPPlaylist playlistWithPlaylistURL:[NSURL URLWithString:playlistUrl] inSession:[SPSession sharedSession] callback:^(SPPlaylist *pl) {
    playlist = pl;
    playlist.delegate = self;

    [SPAsyncLoading waitUntilLoaded:playlist then:^(NSArray *array) {
        NSLog(@"playlist loaded");
    }];
}];

I use the following code to load all of the users playlists:

SPPlaylistContainer *userPlayLists = [[SPSession sharedSession] userPlaylists];

[SPAsyncLoading waitUntilLoaded:userPlayLists then:^(NSArray *result) {

    SPPlaylistContainer *userPlayLists = (SPPlaylistContainer*) [result objectAtIndex:0];

    [SPAsyncLoading waitUntilLoaded:userPlayLists.playlists then:^(NSArray *result) {
          NSLog(@"playlists loaded");
    }];
}];

In case of loading all of the users playlists sometimes 0 playlists are loaded, sometimes all playlists are available but the last waitUntilLoaded won't return.

Is there something wrong with my code?

Emiel
  • 144
  • 4

1 Answers1

0

On this line: [SPAsyncLoading waitUntilLoaded:userPlayLists.playlists then:^(NSArray *result) {

…replace userPlayLists.playlists with userPlayLists.flattenedPlaylists — folders aren't SPAsyncLoading compliant.

Please be aware that +[SPAsyncLoading waitUntilLoaded:then:] has been removed from the latest builds of CocoaLibSpotify, and only +[SPAsyncLoading waitUntilLoaded:timeout:then:] remains. This is to ensure you always get a callback even if stuff isn't loading.

Possible reasons things won't load:

  • The network is being slow and/or is down.
  • The metadata service is slow and/or down.
  • The playlist service is slow and/or down.

Since Spotify is an internet service, you need to be responsive to problems when loading metadata and playlists. +[SPAsyncLoading waitUntilLoaded:timeout:then:] helps you by giving you a list of things that have and haven't loaded if not everything has completed loading when the timeout occurs.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Okay, so probably the playlist service was slow / down when I was testing the app. I tested it again today and it is working fine right now without modifying the code. – Emiel Jul 03 '12 at 14:29