No audio with SDL/C++

半城伤御伤魂 提交于 2021-01-28 05:11:05

问题


void LoadMusic(string path);

Mix_Music* gMusic = NULL;


        LoadMusic("Music/bubble-bobble.mp3");
        if(Mix_PlayingMusic() == 0)
        {
            Mix_PlayMusic(gMusic, -1);
        }

    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
    {
        cout << "Mixer could not initialise. error: " << Mix_GetError();
        return false;
    }


    Mix_FreeMusic(gMusic);
    gMusic = NULL;

void LoadMusic(string path)
{
    gMusic = Mix_LoadMUS(path.c_str());

    if(gMusic == NULL)
    {
        cout << "Failed to load background music! Error: " << Mix_GetError() << endl;
    }
}

Been following a tutorial on how to get audio to work with my game, think something has gone wrong somewhere as it's not playing any sound at all. Not 100% where this is going wrong but does anyone have an idea what I have done wrong and how to fix it?


回答1:


You don't specify your operating system and other important context, but...

If you are running your build under Windows, you might have encountered the same problem as I did:

Surprisingly, the SDL library requires an environment variable in order to play audio at all.

Try adding SDL_AUDIODRIVER=waveout (or alternatively, SDL_AUDIODRIVER=dsound) to your environment (under Windows).



来源:https://stackoverflow.com/questions/22960325/no-audio-with-sdl-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!