我在将NSsound实例添加到NSMutableArray时遇到了问题,我得到的错误是我不能执行[soundFiles addObject:soundObj],因为soundObj是nil。但是如果我使用[soundObj play],它就会播放--所以它是一个实例。
//Name of all the sounds to load in.
sounds = [NSArray arrayWithObjects:
@"sound1",
@"sound2",
nil];
for (int i = 0; i < sounds.count; i++) {
NSString *soundName = [NSString stringWithString:sounds[i]];
NSSound *soundObj = [NSSound soundNamed:soundName];
[soundFiles addObject:soundObj];
}如果我将[soundFiles addObject:soundObj]更改为[soundFiles addObject:soundName],那就没问题了,所以尝试传递NSSound是有问题的
我希望能够预先加载一串非常短的声音,让它们在被调用的那一分钟播放。毫秒对于这个项目来说很重要。
我希望这将允许我做[[soundFiles objectAtIndex:1] play] -因为我在想,这将导致它在播放时比创建NSSound对象更快。
发布于 2014-02-19 13:28:15
您现在可能已经弄清楚了这一点,但我猜您是在创建所有想要处理的声音文件之前编写代码的。因此,当您尝试为那些不存在的文件创建NSSound实例时,它被设置为nil。很难排除故障,因为当您将NSSound指向不存在的文件时,它不会抛出错误。
我有相同的问题,直到我创建了所有我想要使用的声音文件。我只是想发布我的答案,以帮助其他有这个问题的人,因为谷歌搜索没有找到任何帮助。
https://stackoverflow.com/questions/17690147
复制相似问题