Jking
Jking

Reputation: 35

Stopping a System Sound from playing

I can turn off my audio player by using:

- (IBAction)sndOnOff:(id)sender {

    if (_sndBtn.selected == NO) {

        [_sndBtn setSelected:YES];
        [audioPlayer stop];
        }
        else{

        [_sndBtn setSelected:NO];
        [audioPlayer play];
    }

But how do I turn off a System Sound that I've created?

 NSURL *soundURL1 = [[NSBundle mainBundle] URLForResource:@"selectSound"
                                            withExtension:@"wav"];
 AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL1, &sound2);

Upvotes: 2

Views: 2003

Answers (2)

ArthurVonBabylon
ArthurVonBabylon

Reputation: 195

Just do this...

    AudioServicesDisposeSystemSoundID (sound2);

I cannot think of any negative consequences.

Upvotes: 0

Unheilig
Unheilig

Reputation: 16302

There is a reason that we don't get fine control over system sound - because it is supposed to be short (in iOS < 30 seconds) and complete. Imagine, how many times do we experience a system sound cut-off in any OS?

But you could do this:

AudioServicesDisposeSystemSoundID (sound2);

to stop it. But this means you would need to create the sound again by using:

AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL1, &sound2);

And to play it again:

AudioServicesPlaySystemSound(sound2);

You could of course instead to play your "system sound" on AVPlayer and stop it like you do a song, but that would mean it "shouldn't be" a system sound in the first place. Hope this helps.

Upvotes: 4

Related Questions