我们正在开发 SpriteKit 游戏。为了更好地控制音效,我们从使用 SKAudioNode 改为使用一些 AVAudioPlayers。虽然在游戏、帧速率和声音方面一切似乎都运行良好,但在物理设备上进行测试时,我们偶尔会在控制台输出中看到错误(?)消息:
... [一般] __CFRunLoopModeFindSourceForMachPort 对于模式“kCFRunLoopDefaultMode”livePort 返回 NULL:#####
当它发生时,它似乎并没有真正造成任何伤害(没有声音故障或帧速率或其他任何问题),但不准确理解该消息的含义以及它发生的原因让我们感到紧张。
细节:
游戏都是标准的 SpriteKit,所有事件都由 SKActions 驱动,没有什么不寻常的。
AVFoundation 东西的用途如下。应用程序声音的初始化:
class Sounds {
let soundQueue: DispatchQueue
init() {
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error.localizedDescription)
}
soundQueue = DispatchQueue.global(qos: .background)
}
func execute(_ soundActions: @escaping () -> Void) {
soundQueue.async(execute: soundActions)
}
}
Run Code Online (Sandbox Code Playgroud)
创建各种音效播放器:
guard let player = try? AVAudioPlayer(contentsOf: url) else {
fatalError("Unable to instantiate AVAudioPlayer")
}
player.prepareToPlay()
Run Code Online (Sandbox Code Playgroud)
播放音效:
let pan = stereoBalance(...)
sounds.execute {
if player.pan != …Run Code Online (Sandbox Code Playgroud)