Stop effect in cocos2d?

after such a big search, I could not find any solution to stop the effect in cocos2d.

my effect reproduces the sound that was taken from the database, so in order to stop this particular sound, I have to:

[[SimpleAudioEngine sharedEngine] stopEffect:[NSString stringWithFormat:@"%@.wav",sound]]; 

BUT I got a warning: stopEffect makes an integer from a pointer without casting.

why? How can I stop all the sounds that play immediately? or not specific? any other way?

Many thanks.

+6
source share
3 answers

ok you do it:

 ALuint soundEffectID; //to start soundEffectID=[[SimpleAudioEngine sharedEngine] playEffect:@"my sound"]; //to stop [[SimpleAudioEngine sharedEngine] stopEffect:soundEffectID]; 
+20
source

If you do not have soundEffectID, you can do the following. This helped me solve my problem.

 static NSMutableArray *soundsIdArr; @implementation MusicAndSound //It must be run before using sound +(void)initSound { NSLog(@"initSound"); soundsIdArr = [NSMutableArray arrayWithCapacity:0]; [soundsIdArr retain]; } +(void)playSound:(NSString *)fileName { [[SimpleAudioEngine sharedEngine] setEffectsVolume:1.0]; soundEffectID = [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]]; [soundsIdArr addObject:[NSString stringWithFormat:@"%i", soundEffectID]]; } +(void)stopAllSounds { [[SimpleAudioEngine sharedEngine] setEffectsVolume:0.0]; for (int i=0; i<[soundsIdArr count]; i++) { [[SimpleAudioEngine sharedEngine] stopEffect:[[soundsIdArr objectAtIndex:i] intValue]]; } [soundsIdArr removeAllObjects]; } - (void)dealloc { [soundsIdArr release]; [super dealloc]; } @end 
+8
source

Something else...

If you want to stop all running sounds, then

 [SimpleAudioEngine end]; 

but it will also disable sharedEngine, so you need to call "SharedEngine" if you want to play the sound again :)

0
source

Source: https://habr.com/ru/post/896078/


All Articles