iphone – 如何创建SystemSoundID数组

我似乎无法弄明白.

我可以播放一个声音:

- (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是一个完整的非类型类型,所以你需要使用像 NSNumber这样的包装器将它存储在像NSArray这样的Cocoa容器中:

// 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);

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...