SFML community forums
Help => Audio => Topic started by: thed on August 12, 2008, 01:14:22 pm
-
Hello all. I have a simple source file (see below) to play an ogg file. Compiling with MinGW/MSYS on Windows XP using
gcc filename.c -o filename.exe -lcsfml-audio
or
gcc filename.c -o filename.exe -lcsfml-audio-d
appears to create the executable, however, when the executable is activated, a (command-prompt) window appears for an instant and then quickly disappears, with no sound being played and no error messages being displayed. The ogg file is located in the same location as the executable. When the ogg file referred to in the script is absent, I receive a "Failed to open 'absentfile.ogg' for reading" error message before the program shuts down. The SFML code i'm using is:
#include <SFML/Audio.h>
main()
{
sfMusic* Music;
/* Load a music to play */
Music = sfMusic_CreateFromFile("soundfile.ogg");
/* Play the music */
sfMusic_Play(Music);
/* Cleanup resources */
sfMusic_Destroy(Music);
}
Any suggestions would be appreciated. Thanks.
-
Hi,
all music playing func in SFML are threaded, so to keep your app open when your sound is played, you need to add something like that :
while (sfMusic_GetStatus == sfPlaying)
sfSleep(0.1f);
-
Thanks SirJulio.
I modified your suggested code to:
while (sfPlaying)
sfSleep(0.1f);
and it worked a treat. Many thanks.