user731501
user731501

Reputation: 19

Stopping all sounds at once?

Hello I have 16 sounds in a view. And they loops etc. I want a rect button where you tap it all the sounds stop. Here is the code i used for one of the sounds, its the same for the rest.#

- (IBAction)twoSound:(id)sender; {
    if (twoAudio && twoAudio.playing) {
        [twoAudio stop];
        [twoAudio release];
        twoAudio = nil;
        return;
    }    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"wav"];
    if (twoAudio) [twoAudio release];
    NSError *error = nil;
    twoAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
    if (error)
        NSLog(@"%@",[error localizedDescription]);
    twoAudio.delegate = self;
    [twoAudio play];    

}

I tried

-(IBAction)goStop:(id)sender; {

    [oneAudio, twoAudio, threeAudio, fourAudio, fiveAudio, sixAudio, sevenAudio, eightAudio, nineAudio, tenAudio, elevenAudio, twelveAudio, thirteenAudio, fourteenAudio, fifthteenAudio, sixteenAudio stop]; 
}

But that didnt work.

Thanks

Upvotes: 0

Views: 573

Answers (1)

albianto
albianto

Reputation: 4152

I think you have to use an NSArray instead of many sound objects. So you can easily fill the array with the 12 sounds and then you can use a "for" cycle to stop them all.

Upvotes: 3

Related Questions