0

I am writing a Spotify app in C#.

I am currently verifying that the sp_session_process_events() call is working properly. Trying to be very scientific about it, I've been using the out parameter nextTimeout to try and prevent the need for the lib to call NotifyMainThreadCallback.

The call seem to be as frequent with that feature as without it. The value of nextTimeout does not seem to be that valid everytime either. Below is a short example when I am only calling sp_session_process_events when required bĂ˝ NotifyMainThreadCallback.

00:00:08.299: - NotifyMainThreadCallback
00:00:08.312: sp_session_process_events() next process requested in 1000 ms
00:00:08.376: - NotifyMainThreadCallback
00:00:08.381: - NotifyMainThreadCallback
00:00:08.389: sp_session_process_events() next process requested in 922 ms
00:00:08.396: - UserinfoUpdatedCallback
00:00:08.401: - NotifyMainThreadCallback
00:00:08.409: sp_session_process_events() next process requested in 15 ms
00:00:08.415: - MetadataUpdatedCallback
00:00:08.419: sp_session_process_events() next process requested in 891 ms

So why use the nextTimeout at all? As far as I can see it can be ignored.

bes51659
  • 28
  • 4

1 Answers1

0

The next_timeout value is there to prevent you from calling sp_session_process_events too frequently, and is not necessarily intended to reduce the number of main thread 'wake-ups'. I don't see anything unusual about the timeout values you're seeing.

The notify_main_thread callback is often invoked from sp_session_process_events, which you should be calling from the main thread anyway. This shouldn't cause you huge problems. I suppose you could add some extra logic to stay in the event loop rather than signalling in those cases, but that could require more synchronisation than you already have.

paddy
  • 60,864
  • 6
  • 61
  • 103
  • If I get you correct, I will be fine just waiting for the "notify_main_thread" call and not call "sp_session_process_events" on my own initiative at "nextTimeout" (or periodically). What worried me was if there was a situation where libspotify required service without sending "notify_main_thread". – bes51659 May 06 '14 at 20:39
  • That's not correct. You need to call `sp_session_process_events`, or you'll find that your `notify_main_thread` callback doesn't always get called, and the operations you requested (*eg* login) don't do anything. Bottom line is that you should use the SDK the way it is designed to be used. Look at the examples provided with it to see how to run the main thread. – paddy May 06 '14 at 22:12
  • Makes sense. I will take your advice. But I was confused as jukebox.c does not call process_events until it has received its first notify_main (or end_of_track). But from then on it calls it at every notify_main _and_ nextTimeout. I then removed nextTimeout for test and it still worked. Hence the question. The rest is history haha – bes51659 May 07 '14 at 07:32