Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problems opening sound files  (Read 4341 times)

0 Members and 1 Guest are viewing this topic.

pabloist

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problems opening sound files
« 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.

Code: [Select]
#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]

pabloist

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problems opening sound files
« Reply #1 on: January 12, 2011, 11:39:38 pm »
No idea? :/

Zcool31

  • Newbie
  • *
  • Posts: 13
    • View Profile
Problems opening sound files
« Reply #2 on: January 13, 2011, 12:01:39 am »
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.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Problems opening sound files
« Reply #3 on: January 13, 2011, 09:45:09 am »
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 :(
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Problems opening sound files
« Reply #4 on: January 13, 2011, 12:30:26 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pabloist

  • Newbie
  • *
  • Posts: 26
    • View Profile
Problems opening sound files
« Reply #5 on: January 14, 2011, 12:59:46 am »
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!

 

anything