gpt4 book ai didi

tvos - 如何在 tvOS 中覆盖焦点引擎更新声音

转载 作者:行者123 更新时间:2023-12-04 05:32:46 25 4
gpt4 key购买 nike

我试图覆盖在 tvOS 上进行焦点更改时播放的声音,但我似乎找不到任何表明这是否可能的信息。我稍微浏览了一下 Apple 文档,并查看了一些声音 API,但似乎都不合适。有人知道这是否可能吗?如果可能的话,如何实现?

最佳答案

这可以通过 soundIdentifierForFocusUpdate 实现,在 tvOS 11 中添加到 SDK 中

使用此方法,您可以自定义或删除焦点更新时播放的 tvOS 默认声音。

要删除声音,您可以返回 UIFocusSoundIdentifier.none

override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {    
return UIFocusSoundIdentifier.none
}

要使用不同的声音,您必须在目标中包含新的声音文件,并按如下所示加载:

let myPing = UIFocusSoundIdentifier.init(rawValue: "customPing")
let soundURL = Bundle.main.url(forResource: "ping", withExtension: "aif")!
UIFocusSystem.register(_: soundURL, forSoundIdentifier: myPing)

然后你必须从 soundIdentifierForFocusUpdate 返回新的声音:

override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {    
return myPing
}

Apple 在以下链接中记录了所有内容: Using Custom Sounds for Focus Movement

关于tvos - 如何在 tvOS 中覆盖焦点引擎更新声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197019/

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