Why calling audioplayer.play(atTime: delay) makes no sound regardless of the value of delay

帅比萌擦擦* 提交于 2019-12-11 05:39:43

问题


Expect:

When audioplayer.play(atTime: 1) is called, a timer resets to 0, and the audioplayer is played at the 1st second

Reality:

I tried delay = 0.000000001, 1, 100000000, but regardless, no noise would ever be played. The code was clearly executed however (because "function was called" appeared in console)

Why the discrepancy?

C = AVAudioPlayer() // assume other setups are done
C.play(atTime: 1)
print("function was called")

回答1:


according to the official API Reference (translation to swift 3 by me):

Declaration

func play(atTime time: TimeInterval) -> Bool

Parameters

time:

The absolute audio output device time to begin playback. The value that you provide to the time parameter must be greater than the device’s current time. You can delay the start of playback by using code like this:

let playbackDelay = 3.0              // must be ≥ 0
myAudioPlayer.play(atTime: myAudioPlayer.deviceCurrentTime + playbackDelay)


来源:https://stackoverflow.com/questions/43899431/why-calling-audioplayer-playattime-delay-makes-no-sound-regardless-of-the-val

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