使用播放列表Spotify加载跟踪

时间:2012-09-19 10:19:42

标签: iphone cocoalibspotify-2.0

我正在使用cocoalibspotify。我想知道如何从SPPlaylist获得SPPlaylistItem?我有自己的播放列表。如何使用播放列表(按名称)获取播放列表?

1 个答案:

答案 0 :(得分:0)

呵呵..最后我得到了答案。我找到了从播放列表中获取播放列表的方法。

在我的研究过程中,我发现播放列表项目来自关键路径@unionOfArrays.items。因此,通过删除,我只能获取播放列表列表,而不是playlistitem。

请参阅我的代码:

    // arrPlaylist -> mutablearray which stores the value of loaded playlist in order to use it later 
    // tblPlaylist -> Tablename which displays list of playlist. 

[SPAsyncLoading waitUntilLoaded:[SPSession sharedSession] timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedession, NSArray *notLoadedSession) 
    {
        // The session is logged in and loaded — now wait for the userPlaylists to load.
        NSLog(@"[%@ %@]: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), @"Session loaded.");

        [SPAsyncLoading waitUntilLoaded:[SPSession sharedSession].userPlaylists timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedContainers, NSArray *notLoadedContainers) 
        {
            // User playlists are loaded — wait for playlists to load their metadata.
            NSLog(@"[%@ %@]: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), @"Container loaded.");

            NSMutableArray *playlists = [NSMutableArray array];
            [playlists addObject:[SPSession sharedSession].starredPlaylist];
            [playlists addObject:[SPSession sharedSession].inboxPlaylist];
            [playlists addObjectsFromArray:[SPSession sharedSession].userPlaylists.flattenedPlaylists];

            [SPAsyncLoading waitUntilLoaded:playlists timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedPlaylists, NSArray *notLoadedPlaylists) 
            {
                // All of our playlists have loaded their metadata — wait for all tracks to load their metadata.
                NSLog(@"[%@ %@]: %@ of %@ playlists loaded.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), 
                      [NSNumber numberWithInteger:loadedPlaylists.count], [NSNumber numberWithInteger:loadedPlaylists.count + notLoadedPlaylists.count]);
                            NSLog(@"loadedPlaylists >> %@",loadedPlaylists);

                arrPlaylist = [[NSMutableArray alloc] initWithArray:loadedPlaylists];
                NSLog(@"arrPlaylist >> %@",arrPlaylist);

                [tblPlaylist reloadData];
            }];
        }];
    }];