jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.84k stars 462 forks source link

Elapsed Time not Sync #475

Closed Barrie99 closed 7 years ago

Barrie99 commented 7 years ago

Hi Jishi,

First of all, great job on the API. Just began using it today and it's really a nice piece of work! I'm writing a piece of code (currently mostly PHP) to control Philips Hue lights depending on the track playing.. Or to be more exact: to the exact point in the track for e.g. beatsync purposes.

This works nice, but sometimes the elapsed time in the api is off by somewhere between +3 and -3 seconds compared to the Sonos controller App. Is it possible to make it more 'exact'?

Thanks! And again, great job!

jishi commented 7 years ago

I have seen that my time and the controller usually differs with around 1 sec, but it is supposed to be in sync according to the time reported by the player. The only discrepancy that should occur, is the latency that would be introduced when fetching the currently elapsed time. It keeps an internal state time in order to provide a relevant time on each request without calling the player.

The latency to the player should be low (<500ms) unless you have network congestion or the player has a high load.

Given my observations I think I do a similar thing as the official controller (syncing time with the player every 15 sec or when you time seek in a track), so I'm not sure what would actually make it out of sync, unless the internal clock on the device you are running the API on is skewing dramatically (which is unlikely).

However, if you are requiring beat sync on a ms-scale, it will never be exact enough, I'm afraid.