gpt4 book ai didi

swift - 为什么调用 audioplayer.play(atTime : delay) makes no sound regardless of the value of delay

转载 作者:行者123 更新时间:2023-11-28 06:20:04 31 4
gpt4 key购买 nike

期待:

当 audioplayer.play(atTime: 1) 被调用时,定时器重置为 0,音频播放器在第 1 秒播放

现实:

我试过 delay = 0.000000001, 1, 100000000,但无论如何,都不会播放任何噪音。然而,代码显然被执行了(因为“函数被调用”出现在控制台中)

为什么会出现差异?

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

最佳答案

根据官方API Reference(由我翻译成swift 3):

声明

func play(atTime time: TimeInterval) -> Bool

参数

时间:

开始播放的绝对音频输出设备时间。您提供给时间参数的值必须大于设备的当前时间。您可以使用如下代码延迟开始播放:

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

关于swift - 为什么调用 audioplayer.play(atTime : delay) makes no sound regardless of the value of delay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43899431/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com