I'm having the need to play a sfx in a loop and to be able to stop it when needed. I was able to do the loop by doing this:
-(ALuint) playEffect:(NSString*) filename :(bool) loop
{
if(mute)
return -1;
NSNumber* soundId = (NSNumber*)[loadedEffects objectForKey:filename];
if(soundId == nil)
{
[self preloadEffect:filename];
soundId = (NSNumber*)[loadedEffects objectForKey:filename];
}
return [soundEngine playSound:[soundId intValue] channelGroupId:0 pitch:1.0f pan:0 gain:1.0f loop:loop];
}
Only difference is the loop variable in the method. I then tried to do something that would allow me to stop it:
-(void) stopEffect:(NSString*) filename
{
if(mute)
return;
NSNumber* soundId = (NSNumber*)[loadedEffects objectForKey:filename];
if(soundId == nil)
{
return;
}
[soundEngine stopSound:[soundId intValue]];
}
But it doesn't stop the sound effect.
The alSourceStop inside the stopSound is called but nothing happens. Does anyone know of some other way of doing this?
Thanks,
João