0

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

lufinkey
  • 342
  • 4
  • 15
  • I can't explain this, but my own experience with SLD_mixer is that it really is bare-bones and has a few little things like this. –  May 30 '15 at 20:30
  • 1
    Do you know of a possibly better MP3 player library? I'm basically looking for something that I can statically compile against, and it just has a class called Music or something that makes it super simple to load the MP3 file and play it. I really don't want to deal with decoders or anything like that – lufinkey May 30 '15 at 20:32
  • No its a something I keep wondering every time I have todo audio. Then I spend a week poking about and end up sticking with SDL_mixer. I did look at http://audiere.sourceforge.net/ a while ago and was tempted. A little more complicated but not overly so. –  May 30 '15 at 20:40
  • the posted code is C++, so suggest removing the 'C' tag – user3629249 May 30 '15 at 20:46

0 Answers0