So I'm having issues with SDL_mixer, and it seems it plays fine on a good amount of mp3s (although "fine". I noticed that at the beginning of some MP3s there's a small segment of sound corruption, and then it starts playing) but on some MP3 files, there's just absolute silence. It doesn't seem to play anything. And Mix_PlayMusic doesn't seem to return an error, nor does anything else, but it just seems to not make a single sound. Occasionally I'll get a random "Access Reading Violation" when trying to play those files, but every other time, it's just silence.
Here is the code that I'm using to play the MP3 file:
#include "SDL.h"
#include "SDL_mixer.h"
#include <iostream>
bool initLibs()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
if(Mix_Init(flags)!=flags)
{
return false;
}
//Initialize SDL_mixer
if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, 2, 4096 ) == -1 )
{
return false;
}
//If everything initialized fine
return true;
}
int main(int argc, char* argv[])
{
if(!initLibs())
{
std::cout << "error loading libraries" << std::endl;
}
Mix_Music* music = Mix_LoadMUS("test.mp3");
if(music == nullptr)
{
std::cout << "error loading music: " << Mix_GetError() << std::endl;
}
else
{
if(Mix_PlayMusic(music, -1) == -1)
{
std::cout << "error playing music: " << Mix_GetError() << std::endl;
}
}
SDL_Delay(30000);
system("PAUSE");
Mix_HaltMusic();
Mix_FreeMusic(music);
system("PAUSE");
return 0;
}
I was examining the differences in the MP3 files, and it seems that the only real difference is that the ones with LAME3.99 encoding are the ones that don't seem to work. Is anybody able to explain this?
EDIT: After more testing, it also seems to happen on other ones