Search code examples
spotifycocoalibspotify-2.0libspotify

Playlist loaded property is YES but playlist.items have null items inside


I'm using the following code to load a playlist

-(void)loadPlaylist:(NSString *)playlistURI withCompletionBlock:(spotifycompletionWithData)completionBlock andfailed:(failedBlock)failedBlock {

    NSURL *playlistURL = [NSURL URLWithString:playlistURI];
    [[SPSession sharedSession] playlistForURL:playlistURL callback:^(SPPlaylist *playlist) {

    [SPAsyncLoading waitUntilLoaded:playlist timeout:kSPAsyncLoadingDefaultTimeout+10 then:^(NSArray *loadedItems, NSArray *notLoadedItems) {

       if(notLoadedItems.count >= 1){

           [SVProgressHUD dismiss];
           failedBlock();
           return;
       }
       self.playlist = [loadedItems lastObject];
   }];
 }];
}

I'm observing the playlist.loaded property and I see its YES but when I'm looking into the playlist.items lots of them are null. What can I do?


Solution

  • The playlist.loaded == YES just means that the playlist's own metadata is loaded - the name, owner, number of items etc. The items themselves load separately, so you need to separately use SPAsyncLoading to load them.

    Note that loading the entire contents of a playlist at once is a pretty bad idea - playlists get huge, and if you try to load 10,000 items at once things are going to get bad fast on an iOS device.

    Instead, you should consider loading the items in chunks as the user scrolls around your UI.