如何播放Spotify播放列表

时间:2015-08-05 22:03:14

标签: ios iphone spotify playlist

我正确检索了我已登录用户的Spotify播放列表:

- (IBAction)loadPlaylist{
    SPTAuth *auth = [SPTAuth defaultInstance];
    [SPTPlaylistList playlistsForUserWithSession:auth.session callback:^(NSError *error, id object) {
       SPTListPage *pl= object;
       NSLog(@"%@ my playlist items",pl.items);
    }];
}

但是,我不明白如何开始播放此播放列表。

2 个答案:

答案 0 :(得分:1)

检索所有播放列表并将其传递给播放器。

 [self.player loginWithSession:auth.session callback:^(NSError *error) {

    if (error != nil) {
        NSLog(@"*** Error occurred while trying to log in %@", error);
        return;
    }

    [SPTPlaylistList playlistsForUserWithSession:auth.session callback:^(NSError *error, id object) {
        if (!error) {
          NSURL *playlistURL = nil;
          SPTListPage *pl= object;

         if(pl != nil && pl.items.count > 0)
            playlistURL = [pl.items[1] uri];

        NSURLRequest *playlistReq = [SPTPlaylistSnapshot createRequestForPlaylistWithURI:playlistURL accessToken:auth.session.accessToken error:nil];

        [[SPTRequest sharedHandler] performRequest:playlistReq callback:^(NSError *error, NSURLResponse *response, NSData *data) {
            if (error != nil) {
                NSLog(@"*** Failed to get playlist %@", error);
                return;
            }

            SPTPlaylistSnapshot *playlistSnapshot = [SPTPlaylistSnapshot playlistSnapshotFromData:data withResponse:response error:nil];

            [self.player playURIs:playlistSnapshot.firstTrackPage.items fromIndex:0 callback:nil];
        }];

        }
      }];

答案 1 :(得分:0)

检查以下示例代码:

 id plistRep = [[NSUserDefaults standardUserDefaults] valueForKey:@"SpotifySession"];
      SPTSession *session = [[SPTSession alloc] initWithPropertyListRepresentation:plistRep];
    [SPTRequest playlistsForUser:[session canonicalUsername] withSession:session callback:^(NSError *error, id object) {
        SPTPlaylistList *playlist = (SPTPlaylistList *)object;
        for (SPTPartialPlaylist *item in [playlist items]) {
            NSLog(@"Playlist %@", [item name]);
        }
    }];