Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synchronize an audio on 2 or more ios devices

Tags:

ios

iphone

I have to perform an action (play song at a time on multiple devices without lag) at a given point of time. My requirement is that the app should not use any internet connection. So I need an exact point of time when to play data(Audio)]

I have already tried following:

  1. Play song after 5 seconds on all devices. (still causes lag of milliseconds)
  2. Send a small text notification to identify playing of the song and then start playing on all devices. But sending and receiving this notification takes time of milliseconds :(:(
  3. Set time to automatic on all devices and then checked time difference of text message passing, It has milliseconds gap in each testing.
like image 601
Sundeep Saluja Avatar asked Oct 11 '13 09:10

Sundeep Saluja


People also ask

Can you sync 2 iPhones together to play music?

Seedio is a new app that lets you play local iPhone music across multiple devices. The app uses a Wi-Fi network to beam the track to other iPhones in your vicinity and synchronizes the playback. To use the developer's words, the app emulates "one perfectly synchronized loudspeaker" across multiple devices.

How do you sync music to multiple devices?

AmpMe is also a great music sync app for iPhone and Android users to sync music across other devices. It allows you to stream music from your music library, YouTube, Spotify, Soundcloud, and Bandcamp. You can sync music with your friends nearby or who are far away from you even across the world.

How do I stream audio to multiple devices?

Android users need to go to Bluetooth Settings and pair either Bluetooth headphones or speakers one by one. Once connected, tap the three-dot icon on the right and click on Advanced Settings. Toggle on the 'dual audio' option if not already turned on. This should enable users to connect to two devices at once.

How many devices can share audio iOS?

However, to make things simpler, Apple with iOS 13.2 update has added a new feature called Share Audio and it allows users to listen to the same audio on two different Bluetooth devices at the same time.


1 Answers

First you need to synchronize the 2 devices internal time. Apparently the most accurate clock you can have on iOS is the absolute time by doing :

CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();

Then you need to send this time from device A to device B retrieve the difference on device B and send it back to A , then compare the difference with the time spent in the network transaction. In this way you can have a quite accurate synchronisation of the 2 devices time. (This is presuming the network time is symmetric between request and response and that there is not much overhead on your calculation on device B).

enter image description here

From there you can easily instantiate 2 AVAudioPlayer on the devices set the song and call prepareToPlay and finally fire the play method according to the delay on the synch. This should give you a not noticeable precision.

Another route you can take is the one of placing an AudioUnit on the second device connected to the microphone in order to sync the music accordingly to the first device emitted sound.

like image 176
cescofry Avatar answered Sep 29 '22 17:09

cescofry