don't play non wav sound effects if music is playing

This commit is contained in:
mrdude2478 2023-10-06 13:23:45 +01:00
parent 695d477578
commit adbf44ee5c
2 changed files with 19 additions and 15 deletions

View File

@ -150,7 +150,7 @@ namespace inst::ui {
const char* x = loadsound.c_str(); const char* x = loadsound.c_str();
audio = Mix_LoadMUS(x); audio = Mix_LoadMUS(x);
if (audio != NULL) { if (audio != NULL) {
Mix_PlayMusic(audio, -1); //loop "infinitely" Mix_PlayMusic(audio, -1); //-1 loop "infinitely"
} }
} }

View File

@ -306,6 +306,9 @@ namespace inst::util {
playWav(audioPath); playWav(audioPath);
return; return;
} }
//check if music is already playing, if not play something.
if (Mix_PlayingMusic() == 0) {
//if not wav try to play //if not wav try to play
SDL_Init(SDL_INIT_AUDIO); SDL_Init(SDL_INIT_AUDIO);
Mix_Init(MIX_INIT_MP3); //enable mp3 support Mix_Init(MIX_INIT_MP3); //enable mp3 support
@ -318,8 +321,9 @@ namespace inst::util {
music = Mix_LoadMUS(x); music = Mix_LoadMUS(x);
if (music != NULL) { if (music != NULL) {
Mix_PlayMusic(music, 1); Mix_PlayMusic(music, 1);
return;
} }
else {
Mix_HaltChannel(-1); Mix_HaltChannel(-1);
Mix_FreeMusic(music); Mix_FreeMusic(music);
Mix_CloseAudio(); Mix_CloseAudio();