Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether a sound effect is currently playing in SimpleAudioEngine

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?

like image 725
gebirgsbärbel Avatar asked Sep 16 '11 11:09

gebirgsbärbel


1 Answers

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.

like image 139
Youssef Avatar answered Nov 19 '22 23:11

Youssef