My program needs to stop playing sound if certain point is in range, for that I have class with function run() which runs on seperate thread and plays sound using SDL.h and SDL_mixer.h:
void SoundCheck::run()
{
Mix_PlayMusic(music, 1);
while(1)
{
if(normalize(sound[0], range_->getPos()))
{
printf("stop sound\n");
Mix_HaltChannel(-1);
}
sleep(1);
}
}
but when if condition returns true it prints "stop sound" but sound still plays, what seems to be the problem?
Mix_HaltChannel is used to stop a Mix_Chunk after being started with Mix_PlayChannel.
To stop a Mix_Music after being started with Mix_PlayMusic, you must use Mix_HaltMusic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With