title: Synchronize video on multiple clients as accurately as possible?
body: <p>I'd like to synchronize the playing of a video on multiple clients. 
  One client will give the server a URL to a video which can be streamed and click on play then every client is supposed to start playing the video at the exact same time. And while playing it has to be ensured that the every client is still in sync. If someone suddenly stops playing everyone else has to stop too as soon as possible. (At this point the client that stopped would be behind 1 second or so.) Then when the same person starts playing again everyone else would obviously have to wait a second until the one client caught up and then start playing too.  </p>
  
  <p>My first try was to set up a mySQL db and let each client constantly report their current video time to it. The server then calculated if any client in the db is behind and if so, calculated for each client how long they would have to pause to let it catch up.  </p>
  
  <p>But that didn't really work too well. It strongly depended on your latency and I wasn't able to get it reliably working with a delay of &lt;300ms (a really good latency was required for that). </p>
  
  <p>So what could I do to improve it? Should I change my setup (javscript&lt;->ajax&lt;->php&lt;->mySQL)? </p>
  
  <p>How can I reliably calculate the travel time of the response the server sends a client? I mean, I can't just assume the client's system time is the same as the server's... 
  The best thing I could come up with would be something like this:  </p>
  
  <pre><code>var start = new Date().getTime()
  $.post( "sync.php", "")
  .done(function(data) {
      var end = new Date().getTime()/1000;
      var clientServerClientTravelTime = (end-start);
      var estimatedServerClientTravelTime = clientServerClientTravelTime/2;
  });
  </code></pre>
  
  <p>Any idea how I could improve this whole concept?<br>
  Btw video cannot be on my own server.</p>