Is AVAudioPlayerNode isPlaying flag set as soon as scheduleBuffer is called?

人盡茶涼 提交于 2019-12-24 20:13:17

问题


I've got two AVAudioPlayerNodes.

I schedule one using scheduleBuffer.

I want to cancel it before it starts but not if it has already started.

How do I know if it has actually started?

The isPlaying flag appears to be set as soon as it is scheduled rather than when it actually starts at the scheduled time.


回答1:


AVAudioPlayerNode takes a render cycle after calling play() before actual audio starts playing. If you are trying to identify the time between play() and audio being played, you can get the playerNode's playerTime and look for negative (or less than specified with play(at:)) sampleTime values. But since you're on different threads than the audio being scheduled, there's still a chance that a render cycle's worth of audio can squeeze out before you stop the player.

let playerTime = playerNode.playerTime(forNodeTime: AVAudioTime.init(hostTime: mach_absolute_time()))
print("sample time \(playerTime.sampleTime)")


来源:https://stackoverflow.com/questions/44789866/is-avaudioplayernode-isplaying-flag-set-as-soon-as-schedulebuffer-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!