recently i made the game in which i introduced the sound using this function
system("canberra-gtk-play -f file_path &")
to play the sound in my game. But actually there are two problems the first one is that when the game quits the whole window closed up but still the sound is being played and the second one is that how to play this sound synchronously with my game so that it sounds good to the player although the sound is played repeatedly but with respect to the frame per second so i want to make it synchronously and also when the ESC key is pressed the sound will stop along the whole game ...i hope i made whole situation clear ...Any help would be appreciable ...Thankx :)
Asked
Active
Viewed 155 times
1

Spunky Jesh
- 11
- 1
-
I'm unfamiliar with the function you used. I always use playsound(). about the ESC part. use the kbhit function inside the game loop. use getch() to know which key was hit. and if esc is hit use exit() – Devang Jayachandran Jun 07 '15 at 18:43
-
dude i exit the game in the same way you described but the sound doesnt stop ...can you plz demonstrate how to use play sound in ubuntu and which header files are included ...thanks – Spunky Jesh Jun 07 '15 at 19:06
-
What library are you using for your game? The call to 'system' just opens a new process like if you executes that command through the terminal, you need to play the sound within your program to have control of it or some way to communicate the other program to stop playing the sound (not recommended for simple applications). Keep in mind that C++ has no native sound output capabilities so a game library might be useful for your project such as SFML, SDL or Allegro – rlam12 Jun 08 '15 at 03:05
-
You're using Ubuntu? I wouldn't know them. Sorry. The function im talking about is in MMSystem.h and links the Winmm.a library.. Don't know if it works in ubuntu – Devang Jayachandran Jun 08 '15 at 04:30