为什么调用audioplayer.play(atTime:delay)不发出声音,而不管delay的值如何 [英] Why calling audioplayer.play(atTime: delay) makes no sound regardless of the value of delay

查看:255
本文介绍了为什么调用audioplayer.play(atTime:delay)不发出声音,而不管delay的值如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

期望:

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

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

现实:

我尝试了延迟= 0.000000001,1,100000000,但是无论如何,都不会播放噪音.但是,代码已明确执行(因为在控制台中出现了已调用功能")

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)

为什么会有差异?

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

推荐答案

根据官方API参考(我翻译成swift 3):

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

func play(atTime time: TimeInterval) -> Bool

参数

时间:

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

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)

这篇关于为什么调用audioplayer.play(atTime:delay)不发出声音,而不管delay的值如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆