gpt4 book ai didi

ios - 在 SceneKit 中停止在节点上播放声音

转载 作者:搜寻专家 更新时间:2023-11-01 06:30:10 26 4
gpt4 key购买 nike

我有以下手势识别器代码,它在点击时发出喇叭声,在松开时停止:

@objc func didPressHorn(_ sender: UILongPressGestureRecognizer) {

let tapLocation = sender.location(in: sceneView)

if sender.state == .began {

if (wasNodeTapped(node: hornNode!, tapLocation: tapLocation)) {
hornNode!.runAction(SCNAction.playAudio(hornSound, waitForCompletion: false), forKey: "Horn")
hornPlaying = true
}

} else if sender.state == .ended {
if hornPlaying {
// tried all the possible solutions, but the sound won't stop
hornNode?.removeAction(forKey: "Horn")
hornNode?.removeAllActions()
hornNode?.isPaused = true
hornSound.volume = 0
hornPlaying = false
print("Horn off") //gets printed!
}
}
}

如您所见,我正在尝试所有可能的解决方案(我知道),并且还打印了打印语句。但是,声音不会关闭。你知道为什么吗?

最佳答案

我不知道这是否是最好的想法/实践,但您可以尝试:self。 hornNode.removeAllAudioPlayers()

希望对您有所帮助!

关于ios - 在 SceneKit 中停止在节点上播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48526143/

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