2

I use this code to get an AVAudioPlayerNode's current time,

    AVAudioTime * nodeTime = _playerNode.lastRenderTime;
    AVAudioTime * playerTime = [_playerNode playerTimeForNodeTime:nodeTime];
    NSTimeInterval seconds = (NSTimeInterval)(playerTime.sampleTime / playerTime.sampleRate);

But, when I called this code by a CADisplayLink, playerTime.sampleTime return -512 or -1024 at first time.

I don't know, is it correct?

Or is there an other way to get AVAudioPlayerNode's current time real-time?

guojing
  • 129
  • 14
  • (Just for other people searching their way here, not posting this as an answer since I'm guessing. Apple is very half-hearted with documentation on this API.) I think this just represents buffer latency. If you see -512 then the first frame of the player is 512 frames away from being played. It's more useful than having it clamped to 0. – Glenn Maynard Jan 30 '23 at 07:14

0 Answers0