2

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Barkypoo
  • 25
  • 1
  • 4
  • Please post a MVCE and the mp3 file. – aram May 17 '18 at 01:35
  • Have you called `Mix_Init` with at least `MIX_INIT_OGG` bit? Is its return value the same as bitmask you passed to it? – keltar May 17 '18 at 07:48
  • For my case on macOS, I need to have `libmpg123` (to play MP3) installed and have its `.dylib` sit at the same directory level as of executable binary file. Same goes for WIndows as I tested it with cross-compile from macOS. As well, you need to call `Mix_Init()` with flags to initialize `SDL_mixer` for file format you aim to use, and check its return result thus you can debug it more precisely what's went wrong. – haxpor Oct 22 '18 at 04:05
  • Try `.\vcpkg install sdl2-mixer[mpg123]` – Iter Ator Jun 24 '23 at 20:37

1 Answers1

2

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/

Attis
  • 573
  • 1
  • 7
  • 19