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

Author Topic: Can't play MP3s with <SFML/Audio>?  (Read 10439 times)

0 Members and 1 Guest are viewing this topic.

AceDawg45

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Can't play MP3s with <SFML/Audio>?
« 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 - 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!

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #1 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.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #2 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.

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Can't play MP3s with <SFML/Audio>?
« Reply #3 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 but I don't see mp3 ever being taken in consideration.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Can't play MP3s with <SFML/Audio>?
« Reply #4 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Re: Can't play MP3s with <SFML/Audio>?
« Reply #5 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #6 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.
Laurent Gomila - SFML developer

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Re: Can't play MP3s with <SFML/Audio>?
« Reply #7 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #8 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).
Laurent Gomila - SFML developer

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Can't play MP3s with <SFML/Audio>?
« Reply #9 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.
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #10 on: July 26, 2014, 02:11:07 pm »
No problem :P
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Can't play MP3s with <SFML/Audio>?
« Reply #11 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #12 on: July 29, 2014, 11:24:26 pm »
The irritating beeping noise is most likely caused by a debug/release mix.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Can't play MP3s with <SFML/Audio>?
« Reply #13 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.)
Back to C++ gamedev with SFML in May 2023

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Can't play MP3s with <SFML/Audio>?
« Reply #14 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).