3

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?

antoyo
  • 11,097
  • 7
  • 51
  • 82
Cynizm
  • 99
  • 1
  • 8

1 Answers1

6

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.

Jason Norris
  • 420
  • 2
  • 5