0

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?

Michael Thelin
  • 4,710
  • 3
  • 23
  • 29
Gilad
  • 43
  • 9

1 Answers1

1

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.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • what do you mean by wait longer should i delay the UI? – Gilad Nov 20 '13 at 14:50
  • That part of my answer was a bit confusing - I've removed it. – iKenndac Nov 20 '13 at 16:21
  • from what i understood from you , once i've loaded a playlist used KVO on the loaded property it's isn't enough, i should go and SPAsyncloading each track on the playlist? or i've missed something? – Gilad Nov 21 '13 at 07:00