AVAudioPlayer has the function I need - to play audio after a certain time play (atTime:

let shortStartDelay: TimeInterval = 0.1 let now = player.deviceCurrentTime player.play(atTime: now + shortStartDelay) 

It turns out player.deviceCurrentTime is TimeInterval , for example, now I have it equal to 242556.425833583

Does anyone know how he calculates it?

I need to take the system time from the Date () device, add to it, say, 4 seconds and do something like:

 player.play(atTime: Date() + 4) 

How to do it? Or tell me some other player who can do this ...

    1 answer 1

    Good day! deviceCurrentTime is always now. On my simulator, it is reset only after a reboot.

     let systemDate = Date(timeIntervalSinceNow: 4)//Какая-то дата let timeinterval = systemDate.timeIntervalSince(Date()) audioPlayer.play(atTime: audioPlayer.deviceCurrentTime+timeinterval+4) 
    • Thanks, I noticed that on different devices, deviceCurrentTime is not calculated synchronously, somewhere faster, but somewhere slower. Because of this, it is impossible to make a synchronous start on two devices after a long time (even after 5 minutes), only if you synchronize the deviceCurrentTime on both devices right before the launch itself. Every millisecond is important for me, and I don’t want to synchronize every launch of course) - IvanGT