How to create a SystemSoundID array? Using the AudioToolbox Infrastructure

I use to create such sounds:

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

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.

If I put the character and before plasmalaunch1 in the addObject argument, I get

incompatible pointer type warning.

I am trying to create an array of sound effects that I can play later by calling:

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

Recommendations on how to make this work (or the best way to solve this problem) are appreciated!

0
source share
2 answers

SystemSoundID - , ; .

NSArray, . C NSArray.

+2

, . , SystemSoundID. . , NSArray .

    #import <Foundation/Foundation.h>
@import AudioToolbox;

@interface SATSound : NSObject
@property (nonatomic)SystemSoundID id;
- (id)initWithSoundID:(SystemSoundID)id;
@end

/////

#import "SATSound.h"

@implementation SATSound
- (id)initWithSoundID:(SystemSoundID)id
{
    if (self = [super init]) {
        _id = id;
    }
    return self;
}

, SystemSoundID, / , . , , .

+1

Source: https://habr.com/ru/post/1754034/


All Articles