c++ - Sounds not playing on my code -
i learning sfml library version 2.2, sounds won't playing. compile, , run program on ubuntu 14.04. here's program
#include "sfml/audio.hpp" #include <stdio.h> #include <iostream> using namespace std; using namespace sf; soundbuffer buffer; sound audio; int main(int argc, char* argv[]) { if(buffer.loadfromfile(argv[1])) cout << "sounds loaded" << endl; audio.setbuffer(buffer); audio.setvolume(100); audio.play(); cout << "yay!" << endl; return 0; }
and here's compiling code:
g++ testaudio.cpp -i <my directory>/sfml-2.2/include/ -l <my directory>/sfml-2.2/lib/ -lsfml-audio -lsfml-system -o testaudio
there's no error in compiling when run program, sounds not coming out. checked volume, nothing has change.
the sfml sound tutorials sounds , music play in separate thread. what's happening program runs, starts playing sound on separate thread, main thread keeps running , hits end of main
function , exits, killing program. in short: program exiting don't hear sound playing.
try calling sf::sleep()
give program time play song before exiting.
Comments
Post a Comment