I've successfully loaded a Spotify track from a playlist (verified by tracing the track name out to the screen), passed it to be played using sp_session_player_load
and sp_session_player_play(sess, 1)
.
However my music_delivery
callback is never called (I've have some trace in there to show when it is). The libspotify FAQ seems to imply that it will be invoked by an internal thread inside the API and I do not need to invoke sp_session_process_events
to start the streaming.
My application is singly threaded so I'm assuming there is no locking issue in my code.
Sources:
libspotify Haskell binding: https://github.com/mrehayden1/libspotify (You will need libspotify installed to get this to compile: https://developer.spotify.com/technologies/libspotify/#download)
The application code: https://github.com/mrehayden1/harmony
A few ideas:
I do not need to invoke
sp_session_process_events
to start the streaming.
This is somewhat correct, however, you must trigger sp_session_process_events
when you get a notify_main_thread
callback — this comes in on another thread, so you need to correctly delegate this back to your main thread to make the call.
Since you mention you only have a single thread, make sure you're not spinning in a tight loop somewhere — something like while (!sp_track_is_loaded(track)) {}
— since a lot of work in libspotify goes on in the thread you make the calls on, doing this will cause libspotify to be unable to do any work, and everything will grind to a halt.
passed it to be played using
sp_session_player_load
andsp_session_player_play(sess, 1)
.
What are the results of these calls? Loading metadata isn't the same as loading for playback, so you might be getting SP_ERROR_IS_LOADING
back from the play call. In addition, the track might not be playable for some other reason, so the error is important.
If you're still having trouble, the problem may be in the bindings or elsewhere in your code. Check the jukebox example that comes with libspotify for an example C implementation of playback.