Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a method in the same time on 2 devices

Tags:

android

I have 2 android phones phones, both connected to the same wifi, both with bluetooth.

I want some method that syncs somehow the phones and starts a function on the same time on both phones.

For example playing a song at the same time.

I already tried with bluetooth but its with lag, sometimes 0.5 secs. I want something in +- 0.01sec if possible.

Someone suggesting playing it in the future with 2-3 seconds, sending the time-stamp, but how do you sync the internal clocks of the devices then ?

like image 529
OWADVL Avatar asked Jan 14 '15 13:01

OWADVL


2 Answers

Before calling that particular method, try to measure the latency between the two devices:

1.First device says Hi(store the current time)

2.Second device receives the Hi.

3.Second device says back Hi !!

4.First device receives the Hi.((storedTime - currentTime) / 2 )

Now you have the latency, send your request to second device to start your particular method and start it on first one after the latency.

Try to measure the latency 5 to 10 times to be more accurate.

like image 150
M. Reza Nasirloo Avatar answered Sep 28 '22 06:09

M. Reza Nasirloo


you have a way to transfer data between the devices right ? if so you can send a time-stamp which is in the future, ex: if the present time stamp is 1421242326 you send 1421242329 or something and start the function at that time on both devices.

like image 22
Dula wnRp Avatar answered Sep 28 '22 08:09

Dula wnRp