1

i made a game in Ubuntu in which i use .wav files to play the sound in the background using this function:-

system("canebrake-gtk-play -f file_path")

But when the sound is played the whole game stops means the animation stops but after the completion of the sound , the game starts again normally....But this is creating a mess for me and showing a very bad impact , so i want to remove this creepy thing from my game ...so any help would be appreciable.. THANKX

  • 2
    Use a thread/subprocess to play the sound but this not a good way actually. Try to use some C++ framework to play the sound. – VP. May 30 '15 at 20:06

2 Answers2

1

system("canebrake-gtk-play -f file_path")

That's going to be executed synchronously from your code. That's why your program is blocked on execution of this.

You might consider to execute that using a fork() and exec()to be executed at background.

Providing a separate thread (instead of a process), is another option.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

Here's a quick and dirty way.

pid_t pid = fork();

if (pid == 0) {
   system("canebrake-gtk-play -f file_path");
   exit(0);
}

You could also use a thread instead of another process.

Maresh
  • 4,644
  • 25
  • 30