user9343576
user9343576

Reputation:

SDL Mix_LoadMUS not loading .mp3

So Apparently i've been trying to load an .mp3 using SDL_mixer. However, this does not work, as opposed to the libsdl wiki: SDL_mixer Mix_LoadMUS

I was hoping for it to work, but when loading and playing the file, the following errors popped in my console app:

Mix_LoadMUS: Unrecognized audio format
Mix_PlayMusic: music parameter was NULL

To my extent, i've been trying to load test.mp3 the following way:

Mix_Music * m_mainMusic;

m_mainMusic = Mix_LoadMUS("test.mp3");
if (m_mainMusic != nullptr)
    printf("Loaded the file\n");
else
    printf("Mix_LoadMUS: %s\n", Mix_GetError());

if (Mix_PlayMusic(m_mainMusic, -1) == -1) 
    printf("Mix_PlayMusic: %s\n", Mix_GetError());

I have obviously initialized the SDL subsystem.

Upvotes: 3

Views: 4152

Answers (2)

mhdi
mhdi

Reputation: 11

I had the same problem. The only thing you need to do is initialize SDL_mixer before loading the music.

And here's a link to Mix_OpenAudio documentation : https://wiki.libsdl.org/SDL2_mixer/Mix_OpenAudio

Mix_Music * m_mainMusic;

if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024) < 0)
    printf("SDL_mixer could not initialize!", Mix_GetError());

m_mainMusic = Mix_LoadMUS("test.mp3");
if (m_mainMusic != nullptr)
    printf("Loaded the file\n");
else
    printf("Mix_LoadMUS: %s\n", Mix_GetError());

if (Mix_PlayMusic(m_mainMusic, -1) == -1) 
    printf("Mix_PlayMusic: %s\n", Mix_GetError());

Upvotes: 1

Attis
Attis

Reputation: 623

With the help of the above explanations I tried to reproduce your issue, and the only thing that caused something similar was the lack of runtime libraries. Make sure that all the necessary libraries are available during runtime (copy them in the folder of your executable or set an environment variable or use static linking.) The runtime libraries distributed with SDL_mixer are the following ones: libmpg123-0, libmodplug-1, libFLAC-8, libogg-0, libopus-0, libopusfile-0, libvorbis-0, libvorbisfile-3 and SDL2_mixer.

These can be acquired here: https://www.libsdl.org/projects/SDL_mixer/

Upvotes: 2

Related Questions