2

I am using libspotify to iterate through a list of spotify usernames (stored in a database), and create a playlist container for these, and retreive all the playlists inside the container, and all the tracks inside every playlist.

I'm doing this as follows:

static sp_playlistcontainer_callbacks pc_callbacks = {
 NULL,
 NULL,
 NULL,
 &container_loaded
};

static sp_playlist_callbacks pl_callbacks = {
 NULL,
 NULL,
 NULL,
 NULL,
 &playlist_callback,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL
};

static void container_loaded(sp_playlistcontainer *pc, void *userdata)
{
 char * username =  ((char *) userdata);
 sp_playlistcontainer_remove_callbacks(pc, &pc_callbacks, username);

 int num_playlists = sp_playlistcontainer_num_playlists(pc);
 std::cout << "User: " << username << " has : " << num_playlists << std::endl;

 //for each playlist, analyse each song
 //sp_playlist currentPlaylist;
 for(int i=0;i<num_playlists;i++)
 {
    sp_playlist * currentPlaylist = sp_playlistcontainer_playlist(pc,i);
    sp_playlist_add_callbacks(currentPlaylist, &pl_callbacks, username);
 }

 sp_playlistcontainer_release(pc);

}

static void playlist_callback(sp_playlist *pl, void *userdata)
{
 char * username =  ((char *) userdata);

 if(!sp_playlist_is_loaded(pl))
 {
    return;
 }
 sp_playlist_remove_callbacks(pl, &pl_callbacks, username);

 int numTracks = sp_playlist_num_tracks(pl);
 for (int i=0;i<numTracks;i++)
 {
    //do track processing  
 }

 std::cout << "Found: " << sp_playlist_name(pl) << std::endl;

}


//main function
//for(int i=0;...
sp_playlistcontainer * plc = sp_session_publishedcontainer_for_user_create(g_session, usernames[i]);
sp_playlistcontainer_add_callbacks(
 plc,
 &pc_callbacks,
 usernames[i]
);
//end for
//end main

//more functions etc...

The playlist container callback works with out any problems, however the playlist callback only works sometimes for some playlists. I can retreive correctly 95% of all playlists each time. I have left the call back for 30 minutes+ without it raising the callback.

Am I missing something or is there a bug here that I need to work around?

Thanks for your time.

Regards, Rob

4

2 回答 2

1

libspotify 需要通过调用 sp_session_process_events 从主线程定期调用,您似乎没有这样做,至少它不是您源代码的一部分。

有关此背景的信息,请参阅常见问题解答:https ://developer.spotify.com/technologies/libspotify/faq/

于 2013-11-26T11:00:36.033 回答
0

您是否已验证无法获取的播放列表已发布以供公众查看?如果播放列表不是由用户发布的,则除非您以他们的身份登录,否则您无法获取该播放列表。

于 2012-06-08T02:57:15.773 回答