如何使SystemSoundIDs的数组?使用AudioToolbox框架 [英] How do I make an array of SystemSoundIDs? Using AudioToolbox framework

查看:150
本文介绍了如何使SystemSoundIDs的数组?使用AudioToolbox框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯了这样的声音创造:

I'm used to creating sounds like this:

NSString *explosionsoundpath = [[NSBundle mainBundle] pathForResource:@"explosion" ofType:@"caf"];
CFURLRef explosionurl = (CFURLRef ) [NSURL fileURLWithPath:explosionsoundpath];
AudioServicesCreateSystemSoundID (explosionurl, &explosion1a);
AudioServicesCreateSystemSoundID (explosionurl, &explosion1b);  

在这里explosion1a和explosion1b的实例变量与.h文件中声明:

where explosion1a and explosion1b are instance variables declared in the .h file with:

SystemSoundID explosion1a;

每当我试图使这个过程在这样一个数组

Whenever I try to make this process in an array like this

    NSString *plasmasoundpath = [[NSBundle mainBundle] pathForResource:@"plasmasound" ofType:@"caf"];
CFURLRef plasmaurl = (CFURLRef ) [NSURL fileURLWithPath:plasmasoundpath];
SystemSoundID plasmalaunch1;
AudioServicesCreateSystemSoundID (plasmaurl, &plasmalaunch1);
[self.plasmasounds addObject:plasmalaunch1];

我得到一个警告:

I get a warning:

"Passing argument 1 of addObject makes pointer from integer without a cast.

如果我把&放大器;在ADDOBJECT参数plasmalaunch1符号之前,我得到一个

If I put the & symbol before plasmalaunch1 in the addObject argument I get an

incompatible pointer type warning.

我试图创造的音效,我以后可以通过调用发挥数组:

I'm trying to create an array of sound effects which I can later play by calling:

SystemSoundID sound = [self.plasmasounds objectAtIndex:i];
AudioServicesPlaySystemSound(sound);

如何使这项工作(或更好的方法来解决这个问题)美联社preciated咨询!

Advice on how to make this work (or a better way to solve this problem) appreciated!

推荐答案

一个SystemSoundID是一个整数值,而不是一个对象;和一个指向一个号码不是指针的一个对象。

A SystemSoundID is a integer value, not an object; and a pointer to a number is not a pointer to an object.

您可以将其存储在一个NSArray,再后来从对象中除去的ID号来播放声音之前封装在对象中的数值。或者你可以在一个C数组,而不是一个NSArray整数值存储。

You could encapsulate the numeric value in an object before storing it in an NSArray, and then later removing the ID number from the object to play the sound. Or you could store the integer value in a C array instead of an NSArray.

这篇关于如何使SystemSoundIDs的数组?使用AudioToolbox框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆