0

I would like to trigger an event (e.g. play music) on multiple iOS devices at the exact same time (by means of milliseconds)

My approach is to keep a socket connection and send a timestamp to iOS devices (10 seconds later from current time) and trigger the event on iOS devices at that timestamp.

Problem is iOS devices might differ 1 or 2 seconds and that would cause a desynchronize. And even timestamps are pointing out the same time on each devices (AFAIK) they are not on millisecond sensivity.

Is there any way to trigger an event simultaneously on multiple devices, or an approach which should be followed?

Bartu
  • 2,189
  • 2
  • 26
  • 50
  • How are these devices connected to each other? Over the Internet? Local network? What type of app is this? – Jim May 10 '13 at 19:59
  • over internet, it will capture sound for 10 seconds on each device and process the captured data – Bartu May 10 '13 at 20:00
  • So these devices aren't near one another? In that case, why does it need to be millisecond precision? The people with the devices aren't going to know one way or the other. Perhaps there's a better way of achieving your goals. What are you trying to do? – Jim May 10 '13 at 20:17
  • actually they are near one another :) i am going to implement a source seperation on sound (if I can achieve syncronization) – Bartu May 10 '13 at 20:23
  • Using Gamekit is as easy as calling `sendDataToAllPlayers:withDataMode:error:`. “The Advanced iOS 6 Developer’s Cookbook” has a chapter on GameKit. – Jano May 10 '13 at 22:43

1 Answers1

1

Don't send the data over the Internet. You can't assume the connection latency will be low enough for your needs. Use Bluetooth instead. You can do with with GameKit, with dns-sd, or with a library like HHServices.

Pick a device that will act as the controller. Apple provide sample code to do so with GameKit, but it's not difficult to think up your own method. When you want to trigger the action, that controller will send a packet over Bluetooth to the other devices.

I doubt you need lower latency than that, but if you do, have the controller send packets to each connected device to ascertain the latency for each connection, have them send their timestamps to the controller, then the controller should be able to calculate a timestamp for each of them that will occur at the same time.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • I tried gamekit(over bluetooth). there is a 30.8ms (given that iOS set time automatically sets exact same time to each device) I tried several ways to record and play that audio to create a complete sync. I calculated a standard deviation of latency between devices and let the host act after that latency, when it sends out data to other device(s). Yet I can hear the difference between devices :S maybe I should try to find a more robust way to detect latency over bluetooth – Bartu May 12 '13 at 01:00