gpt4 book ai didi

ios - 尝试播放音频时出错 : 998: Failure to setup sound, err = -50

转载 作者:行者123 更新时间:2023-11-30 13:08:49 25 4
gpt4 key购买 nike

我试图在两个物体碰撞时播放声音,但每次都会收到此错误。我正在使用 iPhone 6 进行测试。代码如下:

    guard soundEffects[sound] == nil else
{
print("Sound effect \(sound) already exists")
return false
}

guard let soundURL = NSBundle.mainBundle().URLForResource(sound, withExtension:format, subdirectory:path) else
{
print("Error creating URL for resource \(sound)")
return false
}

print(soundURL)

var systemID : SystemSoundID = id

soundEffects[sound] = systemID
print(AudioServicesCreateSystemSoundID(soundURL, &systemID))

id += 1

我尝试像这样玩:

    guard soundEffects[sound] != nil else
{
print("Sound effect '\(sound)' not found")
return false
}

print(soundEffects[sound]!)

AudioServicesPlaySystemSound(soundEffects[sound]!)

文件的格式是wav,我打印了创建方法的代码,该代码为0。我似乎也无法在苹果网站或网络上的其他任何地方找到有关该错误的任何文档。我做错了什么吗?

更新:

显然,将值存储在字典中并稍后加载是导致错误出现的原因。但问题是我需要一本 ID 字典。我应该如何存储 ID 以及为什么存储它会导致错误?

最佳答案

我可以通过这样做解决我的问题:

let systemID : SystemSoundID = someUInt32
soundEffects[sound] = systemID
AudioServicesCreateSystemSoundID(soundURL, &soundEffects[sound]!)
AudioServicesPlaySystemSound(soundEffects[sound]!)

似乎 create 方法执行其操作的对象是您可以调用 play 的唯一对象,因此您需要专门在字典的实例(或您尝试的任何对象)上执行 create 方法。将声音存储在)。

关于ios - 尝试播放音频时出错 : 998: Failure to setup sound, err = -50,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38979102/

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