0

I am trying to get the last 5 songs that a Spotify user has starred. After looking at the Guess the Intro example that Spotify provides, I was able to pull the entire playlist, but I was wondering if there is a way in cocoaLibSpotify for me to only pull a certain number of songs at a time. Below is the function that I am using to get the tracks from the starred playlist:

+ (void)gatherTracksWithBlock:(void (^)(BOOL, NSArray *))block {
    __block SPPlaylist *starred = [SPSession sharedSession].starredPlaylist;
    [SPAsyncLoading waitUntilLoaded:starred timeout:20.0 then:^(NSArray *loadedItems, NSArray *notLoadedItems){

        if ([[starred items] count] == 0) {
            block(NO, nil);
            starred = nil;
            return;
        }

        NSMutableArray *topTracks = [[NSMutableArray alloc] initWithCapacity:[[starred items] count]];

        for (SPPlaylistItem *item in [starred items]) {
            if (item.itemClass == [SPTrack class]) {
                [topTracks addObject:item.item];
            }
        }

        block(YES, topTracks);
        starred = nil;
        return;
    }];
}

Are there any modifications that I can make to get this function to only pull a certain number of tracks at a time? Also, if this is possible, am I able to then skip over the number of tracks that I have pulled previously?

One last question! Is it possible to gather a user's recently played tracks using cocoaLibSpotify? I was looking at older posts and the answer I saw was no, but I was wondering if anything had changed since those posts were closed.

Sorry in advance for the compound questions. It's my first time posting!

Thanks, Tyler

1 Answers1

0

A playlist contains SPPlaylistItem objects, which has a dateAdded property. Once you have the starred playlist's items, sort by that property and you'll have an array in the order of date added — then you just grab the first five items in the list and you're done.

You still can't get recently played tracks.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Hi iKenndac, Thanks for the response! After executing the above function, I currently sort by dateAdded to get the last five tracks. However, I was wondering if there is a way to pull only those five tracks, as I really don't need the rest of the array. Is there any way to do this? Thanks, Tyler – Tyler Fallon Jul 22 '14 at 16:26