2010-07-10 4 views
3

Je n'arrive pas à comprendre.Comment faire un tableau de SystemSoundID

je peux jouer un son avec:

- (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); 
} 

Mais je veux créer un tableau d'objets SystemSoundID. Quand j'essaye de faire ceci je continue à recevoir des erreurs. Quelqu'un peut-il me montrer le code pour créer un tableau de soundFileObjects et comment j'utilise ce tableau dans AudioServicesPlaySystemSound?

+0

J'ai posté une autre réponse à l'aide d'objets [ici ][1]. [1]: http://stackoverflow.com/a/26701297/951349 – smileBot

Répondre

7

SystemSoundID est une intégrale, non classe, type, de sorte que vous aurez besoin d'utiliser un emballage comme NSNumber pour la stocker dans des conteneurs de cacao comme 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); 
Questions connexes