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:
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.
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.
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.
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.
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
).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With