Iphone 如何生成SystemSoundID数组
我似乎想不出来 我可以通过以下方式播放一种声音:Iphone 如何生成SystemSoundID数组,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我似乎想不出来 我可以通过以下方式播放一种声音: - (void) initSounds { // Get the main bundle for the app CFBundleRef mainBundle; mainBundle = CFBundleGetMainBundle (); // Get the URL to the sound file to play soundFileURLRef = CFBundleCopyResourceURL
- (void) initSounds {
// Get the main bundle for the app
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();
// Get the URL to the sound file to play
soundFileURLRef = CFBundleCopyResourceURL (mainBundle,CFSTR ("1"),CFSTR ("wav"),NULL);
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
}
-(void) play {
AudioServicesPlaySystemSound(self.soundFileObject);
}
但是我想创建一个SystemSoundID对象数组。当我尝试这样做时,我总是会出错。有谁能告诉我创建soundFileObjects数组的代码,以及我如何在AudioServicesPlaySystemSound中使用该数组吗?
SystemSoundID
是一个完整的非类类型,因此您需要使用类似于包装器的包装器将其存储在Cocoa容器中,如NSArray
:
// assuming this property:
@property (copy) NSArray *soundFileObjects;
// creating the array:
soundFileObjects = [[NSArray alloc] initWithObjects:
[NSNumber numberWithUnsignedLong:soundId],
// more ?
nil];
// using it, e.g.:
SystemSoundID sid = [[self.soundFileObjects objectAtIndex:0] unsignedLongValue];
AudioServicesPlaySystemSound(sid);
我用objects[here][1]发布了另一个答案。[1]: