AVAudioEngine synchronize with AVPlayer

Is there a way to synchronize AVAudioEngine playback (for audio) in sync with AVPlayer for visual playback? The AVPlayer documentation describes the property "masterClock" as the means to "synchronizing video-only movies with audio played by another source". I cant find any in AVAudioEngine that contains a CMClockRef object.

Replies

To really get an idea of how creating a clock using for example CMAudioClockCreate (on iOS) is useful when assigned to an AVPlayer masterClock and used with the method setRate: time: atHostTime: when syncing with user generated audio, it's recommended that you watch the WWDC presentation from 2012 called "Real-Time Media Effects and Processing during Playback". Starting at 11 minutes into the presentation the subject "Syncronizing Video to Custom Audio" is discussed in depth. However, you'll probably want to start at the beginning to experience an excellent explanation of Time and CMTime and clocks in general.


You'll find this presentation super helpful and I'm sure it will clear up some of the hazy bits.


https://developer.apple.com/videos/wwdc/2012/#517

How would you synchronize AVAudioEngine to AVCaptureSession. What I want to do is to playback custom mixed music while capturing videos. In essence I want to record video with the custom mixed audio. I cant not get the music to always start at the same precise time in the recorded video. AVCaptureSession has a masterClock but it is readonly. Is there a way to synchronize these two objects?

I'm still confused how/where the AVAudioEngine has information / a reference to the CMAudioClock object? Currently trying to do the same exact thing as @iami2

Have you figured this out? Currently trying to do the exact same as you but I keep running into the same question you posted (how the AVAudioEngine has a reference to the CMClock?)