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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.