The question sounds very simple but I couldn't find a way to check if a track uri is correct.
For example, the normal procedure to play a track by a given valid track uri spotify:track:5Z7ygHQo02SUrFmcgpwsKW is:
1) get sp_link* by sp_link_create_from_string(const char *$track_uri)
2) get sp_track* by sp_link_as_track(sp_link*)
3) sp_track_add_ref(sp_track*)
4) if sp_track_error() returns SP_ERROR_OK, or SP_ERROR_IS_LOADING but metadata_updated and
SP_ERROR_OK then sp_session_player_load and sp_session_player_play to load and play the track.
5) sp_track_release() and sp_session_player_unload() when it's the end of track.
When I try to do to play with a correct uri sp_track_error() returns SP_ERROR_IS_LOADING,
metadata_updated never gets called, and of course the program hangs.I have check many uri
and get the same result.
Did I miss something or misunderstand the APIs?
This is the main loop:
pthread_mutex_lock(&g_notify_mutex);
for(;;)
{
if (next_timeout == 0)
{
while(!g_notify_do && !g_playback_done)
{
pthread_cond_wait(&g_notify_cond, &g_notify_mutex);
}
}
else
{
struct timespec ts;
#if _POSIX_TIMERS > 0
clock_gettime(CLOCK_REALTIME, &ts);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif
printf("%d\n",next_timeout);
if((ts.tv_nsec+(next_timeout % 1000) * 1000000)>=1000000000)
{
ts.tv_nsec += (next_timeout % 1000) * 1000000-1000000000;
ts.tv_sec += next_timeout / 1000+1;
}
else
{
ts.tv_sec += next_timeout / 1000;
ts.tv_nsec += (next_timeout % 1000) * 1000000;
}
pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
}
g_notify_do = 0;
pthread_mutex_unlock(&g_notify_mutex);
g_currenttrack= sp_link_as_track(sp_link_create_from_string(spotify:track:1NrJYpdAi7uosDRPmSYrsG));
sp_track_add_ref(g_currenttrack);
if (sp_track_error( g_currenttrack) == SP_ERROR_OK) {
sp_session_player_load(g_sess, g_currenttrack);
sp_session_player_play(g_sess, 1);
}
do
{
sp_session_process_events(g_sess, &next_timeout);
}
while (next_timeout == 0);
pthread_mutex_lock(&g_notify_mutex);
}
I found that metadata_update called by main loop,but when the track has been created this loop will hang out for a long time(about 290s).