I'm trying to find out how to stop a specific sound effect rather than having to stop all of them.

I'm using OALSimpleAudio.

I can't seem to find how to do it. simple google searches result in nothing, which means my searches are crap, it's REALLY easy to do and i'm ... stupid :p, or it isn't possible.

I hope you guys can help me.

In the background i have a humming engine sound, but when the object takes damage, the humming sound is stopped, that's not what i want.

case kStateTakingDamage:
        CCLOG(@"Ship taking damage");
        [self playTakingDamageSound];
        self.characterHealth = self.characterHealth - 1.0f;
        action = [CCActionAnimate actionWithAnimation:damageAnimation];
        [[GameManager sharedGameManager] stopSoundEffect];

- (void) playSoundEffect: (NSString *) soundEffect {
    [self playSoundEffect: soundEffect andLoop: NO];

- (void) playSoundEffect: (NSString *) soundEffect andLoop: (BOOL) loop {
    [[OALSimpleAudio sharedInstance] playEffect:soundEffect loop: loop];

- (void) stopSoundEffect {
    [[OALSimpleAudio sharedInstance] stopAllEffects];

- (id) isSoundPlaying {
    //TODO: find out how this works ;

All you need to to is to store the return value of [OALSimpleAudio playEffect]. The method returns an instance of type id<ALSoundSource>, which means a class that implements the ALSoundSource protocol. This is the actual sound effect object used internally by OAL. If you refer to the documentation, you'll find that id<ALSoundSource> has a stop method.

So all you need to do is basically:

id<ALSoundSource> soundSrc = [[OALSimpleAudio sharedInstance] playEffect:"my_sound.mp3" loop:true];
// play for a while...
if (soundSrc != nil)
    [soundSrc stop];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.