spotify - libspotify:how to play a track from a track uri? -


the question sounds simple couldn't find way check if track uri correct.

for example, normal procedure play track given valid track uri spotify:track:5z7yghqo02surfmcgpwskw is:

1) sp_link* sp_link_create_from_string(const char *$track_uri)

2) sp_track* 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 metadata_updated ,

sp_error_ok sp_session_player_load , sp_session_player_play load , play track.

5) sp_track_release() , sp_session_player_unload() when it's end of track.

when try play correct uri sp_track_error() returns sp_error_is_loading,

metadata_updated never gets called, , of course program hangs.i have check many uri

and same result.

did miss or misunderstand apis?

this 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);           }                 {             sp_session_process_events(g_sess, &next_timeout);         }         while (next_timeout == 0);          pthread_mutex_lock(&g_notify_mutex); } 

i found metadata_update called main loop,but when track has been created loop hang out long time(about 290s).

metadata_updated won't called unless sp_session_process_events() called. reason code stalling 300s because after login, sp_session_process_events() sets next call timeout 300s. after step 3, force own notify main thread, , fix issue. unfortunately don't know why libspotify not send notify main thread @ point. guess we're both missing here.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -