SFML community forums

Help => Audio => Topic started by: AceDawg45 on July 25, 2014, 08:49:02 pm

Title: Can't play MP3s with <SFML/Audio>?
Post by: AceDawg45 on July 25, 2014, 08:49:02 pm
So, first I'll post the code, then explain:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <Windows.h>

int main()
{
        ShowWindow(GetConsoleWindow(), SW_HIDE);
        sf::Music music;
        if (!music.openFromFile("C:\Users\Public\Music\Sample Music\Kalimba.mp3"))
                return -1; // error
        music.play();
        return 0;
}

I am using Visual Studio 2013 Express, and when I run this program, I get an irritating beeping noise and get this message:
Quote
Unhandled exception at 0x0F26DEF8 (msvcr110.dll) in sfmoDemo.exe: 0xC0000005: Access violation reading location 0x00297000.

I don't really know what that means. Is there anything wrong with the code? I got it from the resources page - http://www.sfml-dev.org/tutorials/2.1/audio-sounds.php (http://www.sfml-dev.org/tutorials/2.1/audio-sounds.php) - so I assume it isn't that. Is there a way that I setup SFML wrong? I'd appreciate any help I can get! Thanks!
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Jesper Juhl on July 25, 2014, 09:14:21 pm
Try a .ogg file or other free format.
Mp3 is patent encumbered and I can't remember if it is supported.
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Ixrec on July 25, 2014, 09:26:04 pm
Quoth the FAQ:

What audio formats does SFML support?

In addition to the formats supported by libsndfile (wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64) the Audio module is also capable of playing ogg files. Unfortunatly MP3 is covered by a license from Thompson Multimedia and thus support for it is not included in SFML. For more information regarding the MP3 license, see http://www.mp3licensing.com.
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Strelok on July 25, 2014, 09:35:43 pm
Bear in mind this holds true for SFML 2.1 as it might change in the future versions of SFML https://github.com/SFML/SFML/compare/feature/no_libsndfile (https://github.com/SFML/SFML/compare/feature/no_libsndfile) but I don't see mp3 ever being taken in consideration.
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Nexus on July 25, 2014, 10:39:02 pm
Bear in mind this holds true for SFML 2.1 as it might change in the future versions of SFML
Unless MP3 suddenly gets a different licensing model, this is not likely to happen. The restriction is not a result of the underlying sound library, as such it won't change if libsndfile is replaced.
Title: Re: Re: Can't play MP3s with <SFML/Audio>?
Post by: Strelok on July 25, 2014, 10:47:17 pm
Bear in mind this holds true for SFML 2.1 as it might change in the future versions of SFML
Unless MP3 suddenly gets a different licensing model, this is not likely to happen. The restriction is not a result of the underlying sound library, as such it won't change if libsndfile is replaced.
I was referring to Ixrec's post, I see only vorbis files supported, am I wrong?
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Laurent on July 26, 2014, 12:04:46 am
The list of supported formats is clearly mentioned in the documentation. Please read it.

Future versions won't support MP3, but will provide an easy way to add it with a plugin.
Title: Re: Re: Can't play MP3s with <SFML/Audio>?
Post by: Strelok on July 26, 2014, 12:19:25 am
The list of supported formats is clearly mentioned in the documentation. Please read it.

Future versions won't support MP3, but will provide an easy way to add it with a plugin.
What I don't understand is you added vorbis as dependency, can it support all the aforementioned formats or you're still working on it?
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Laurent on July 26, 2014, 09:44:39 am
I don't know what you're referring to, but so far we are using libsndfile which handles all the formats that we want (and also some that we don't need).

But due to its license, it will soon (2.2 or 2.3) be replaced with lower level libraries (libogg, libvorbis, libflac, ...) and we'll support WAV, OGG/Vorbis and FLAC. This new system will also make it very easy to write extensions to handle other formats. In the end, people will probably be able to use plugins written by the community to extend the set of formats (including MP3, if they can handle the license).
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Strelok on July 26, 2014, 01:12:22 pm
we'll support WAV, OGG/Vorbis and FLAC. This new system will also make it very easy to write extensions to handle other formats. In the end, people will probably be able to use plugins written by the community to extend the set of formats (including MP3, if they can handle the license).
So I was right, the supported formats will change in the next releases. I phrased everything wrong but what I meant was "it's likely the supported formats will change in the future, but mp3 won't be part of the changes" that's why I linked the git branch (https://github.com/SFML/SFML/tree/feature/no_libsndfile).
Sometimes I switch to lazy non sensical english when I'm on my tablet. Sorry for the misunderstanding and thanks for the heads up.  ;D
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Laurent on July 26, 2014, 02:11:07 pm
No problem :P
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Mario on July 29, 2014, 10:14:13 pm
Ignoring licensing/file support, I don't think this should cause any exception to be thrown. Are you sure you're using the correct library version, i.e. SFML compiled with VS 2012 as well?
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Laurent on July 29, 2014, 11:24:26 pm
The irritating beeping noise is most likely caused by a debug/release mix.
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: FRex on July 29, 2014, 11:32:51 pm
And so is the crash, for me it has clear error
Quote
Failed to open sound file "mp3.mp3" (File contains data in an unknown format.)
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: Mario on July 30, 2014, 05:50:40 pm
That error message is fine and intentional, but the program should quite (follow your return -1;) rather than crashing (before leaving SFML).
Title: Re: Can't play MP3s with <SFML/Audio>?
Post by: wintertime on July 31, 2014, 12:53:04 am
Could be because the backslash characters start escape sequences like \Uxxxx, get translated by the compiler wrongly and then result in a runtime crash? You better use only forward slash inside a path (windows understands these, too) and if possible only use a relative path to an .ogg file.