SFML community forums
Help => Audio => Topic started by: pabloist on January 05, 2011, 02:26:01 am
-
I can successfully load and use images, but am having problems doing the same for both sound and music.
#include <SFML/Audio.hpp>
int main()
{
sf::Music Music;
if (!Music.OpenFromFile("mus/chimes.wav"))
return EXIT_FAILURE;
Music.Play();
return EXIT_SUCCESS;
}
Gives me "Failed to open "mus/chimes.wav" for reading", and does the same with sf::SoundBuffer. I am certain the file path is correct, because I have correctly loaded images along similar filepaths (I also attempted reading an image from the same folder, which worked.)
I don't believe the .wav file is corrupted, since I can still play it, and I have attempted this with several files already.
Any ideas on what's wrong? I'm using Windows 7, gcc 4.4, sfml1.6, code::blocks.[/quote]
-
No idea? :/
-
File locations work differently when you run from an IDE than when you run the executable by itself.
When you run your project from an IDE, file directories are relative to the directories for your source. So you'd need to copy your "mus" folder to where you have your main.cpp
When you run your executable (like most people will) file directories start from where the executable is, so you'll place your "mus" folder where you have your Project.exe
You can temporarily bypass the issue by using the absolute path "C:\some foulder\mus\chimes.wav" but this is should be temporary and will break if you move any files.
-
What I learned pretty quickly is to change the Working directory in the project settings. This let you create a "distribution" folder where you have all images, music and so on. But the exe file will still be in the Debug/Release folder. Makes it much easier and cleaner to work with and when you are going to relase it you jsut copy the exe file over to the dist folder :)
It works for SFML but some libraries might not like it. HGE that my university forces me to use ignores the working directory completely and forces you to place everything in the same folder as the exe-file even in an IDE. Which is a real pain :(
-
Are you sure that this is HGE's fault? Normally, the compiler and operating system are responsible to handle paths. HGE can't probably do more than specify a path like "gfx/image.png" and forward it to a loading library.
-
Ah, I understood about relative vs absolute filepath. For some reason, I managed to get it working now. It might have had something to do with the files.. chimes.wav started working, but other files within the folder wouldn't. /shrug
Thanks to those who tried to help!