Looking at the source of jukebox.c it seems like you should make sure that the playlist container is fully loaded before trying to query it for playlists.
So if I understand it correctly you should add a callback for container_loaded
.
I also think you should setup a callback so you will be notified when the user is logged in and when logged in you should try to get the playlist container. Something like this might help:
static sp_playlistcontainer_callbacks pc_callbacks = {
NULL, /* playlist_added */
NULL, /* playlist_removed */
NULL, /* playlist_moved */
&container_loaded,
};
static sp_session_callbacks session_callbacks = {
&logged_in,
¬ify_main_thread,
NULL, /* music_delivery */
NULL, /* metadata_updated */
NULL, /* play_token_lost */
NULL, /* log_message */
NULL /* end_of_track */
};
static void container_loaded(sp_playlistcontainer *pc, void *userdata)
{
// container is fully loaded now it should be safe to query the container
int num_playlists = sp_playlistcontainer_num_playlists(pc);
}
static void logged_in(sp_session *sess, sp_error error)
{
// get playlist when user is logged in
sp_playlistcontainer *pc = sp_session_playlistcontainer(sess);
// add callbacks
sp_playlistcontainer_add_callbacks(
pc,
&pc_callbacks,
NULL);
/* rest of code */
}