Playing mp3/ogg with SDL_Mixer

Hope this is the correct place to ask.

I am trying to load a ogg-file for music (alternatively a mp3-file). My code looks like this:

int result;

auto mixinitflags = MIX_INIT_OGG | MIX_INIT_MP3;
if (mixinitflags != (result = Mix_Init(mixinitflags))) {
printf(“Could not initialize mixer (result: %d).\n”, result);
printf(“Mix_Init: %s\n”, Mix_GetError());
assert(0 == Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 512));
mp3music = Mix_LoadMUS(“res/music.ogg”);
if (!mp3music)
std::cerr << "Failed to load music. " << Mix_GetError() << std::endl;
if (Mix_PlayMusic(mp3music, -1) == -1) {
printf(“Mix_PlayMusic: %s\n”, Mix_GetError());

I use cmake and vcpkg and it works on Mac, but not on Windows. Vcpkg doesnt copy the decoder-libraries so I had to download and copy them to the output-folder by hand (otherwise I get “OGG support not available”). When I do this get “Failed to load music. Unrecognized audio format”. But as I said, only on Windows and not Mac. I’ve tried playing both a ogg and mp3 version and downloaded random ogg-files from the internet to try out but nothing works. The files do play in any other player on Windows (VLC etc).

I have run out of ideas, would appreciate any help immensely!

Since you use vcpkg, you have to install additional “extension” libraries (they are just SDL2_Mixer with more files support). All SDL2_mixer-related vcpkg packages are:

sdl2-mixer:x64-windows                             2.0.4-9          Multi-channel audio mixer library for SDL.
sdl2-mixer[dynamic-load]:x64-windows                                Load plugins with dynamic call
sdl2-mixer[libflac]:x64-windows                                     Support for FLAC audio format.
sdl2-mixer[libmodplug]:x64-windows                                  Support for MOD audio format.
sdl2-mixer[libvorbis]:x64-windows                                   Support for OGG Vorbis audio format.
sdl2-mixer[mpg123]:x64-windows                                      Support for MP3 audio format.
sdl2-mixer[opusfile]:x64-windows                                    Support for Opus audio format.

Just install the ones you need, then try to build your code. It worked for me.