Detect whether a sound effect is currently playing in SimpleAudioEngine
Asked Answered
L

1

6

I want to detect whether [SimpleAudioEngine sharedEngine] is currently playing any effect. For Background music there is a method that gives you the information whether background music is playing:

[[SimpleAudioEngine sharedEngine] isBackgroundMusicPlaying];

Does something similar exist for sound effects? If not how else can I detect whether I am already playing an effect?

Lublin answered 16/9, 2011 at 11:52 Comment(0)
A
3

SimpleAudioEngine Doesn't have a method like isBackgroundMusicPlaying for effects, but you can store a BOOL called isPlaying and use CDSoundSource

CDSoundSource* currentSound = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
[currentSound load:audioFile];
currentSound.delegate = self;
currentSound.backgroundMusic = NO;
isPlaying = YES;
[currentSound play];

Then implement the callback:

- (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource {
    isPlaying = NO;
}

I don't know exactly if that's the correct way to initialise the CDSoundSource since I've stolen shamelessly the code from this topic . Maybe you should take a look at the CDAudioManager Class Reference

Hope this helps to point you in the right direction.

Annul answered 16/9, 2011 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.