Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL_mixer stop playing music on certain event

Tags:

c++

sdl

sdl-mixer

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?

like image 341
Cynizm Avatar asked Nov 22 '25 08:11

Cynizm


1 Answers

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.

like image 149
Jason Norris Avatar answered Nov 23 '25 21:11

Jason Norris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!