I’m writing a C# wrapper around libspotfiy, and have a problem with the track playing. From what I can tell, when I want to start streaming a track for the first time in a session, I should call
sp_session_player_load(sessionHandle, trackHandle)
sp_session_player_play(sessionHandle, true);
This is what I’m doing, and it works fine. The problem start when I want to play something else. With a track still playing, what am I meant to do to play a new one? Should I call
sp_session_player_play(sessionHandle, false);
sp_session_player_unload(sessionHandle);
Before then calling a new round of load/play? I ask because when I do this, I often see my program hang when I call the unload, or call play with an argument of false. I’m using the get_audio_buffer_stats callback. I’ve got appropriate thread syncronisation in place, so I’m wondering if I’mu sing the api incorrectly?
This is exactly what the official Mac and iOS library does, and it works fine:
When playing for the first time:
When playing again:
There are a couple of things you can check, though:
The most common hang I’ve seen is due to how the program implements the
notify_main_threadcallback. When you get this, you must schedule a call sosp_session_process_eventson the main thread in a non-blocking way. I.e., yournotify_main_threadimplementation should return beforesp_session_process_eventsis called on the other thread.Try taking out your
get_audio_buffer_statsimplementation. This Mac/iOS library doesn’t implement this at all – it isn’t required.If this isn’t enough, please try to get a stack trace of the hang. If you catch it in the debugger, hitting pause is often good enough.