如何创建SystemSoundID数组

use*_*734 3 iphone xcode objective-c

我似乎无法弄明白.

我可以播放一个声音:

- (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);
}
Run Code Online (Sandbox Code Playgroud)

但我想创建一个SystemSoundID对象数组.当我尝试这样做时,我不断收到错误.任何人都可以告诉我创建soundFileObjects数组的代码以及我如何在AudioServicesPlaySystemSound中使用该数组?

Geo*_*che 7

SystemSoundID是一个完整的,非类,类型,所以你需要使用一个包装器,如NSNumber将它存储在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);
Run Code Online (Sandbox Code Playgroud)