SDL_Mixer - how to toggle sound off/on?

I want ot add a sound on/off button to my game. I’ve looked thru the SDL_Mixer API and I haven’t seen any function that toggle sound on/off (globally).
Do I have to keep track of all sounds that are playing (and music) and set volume to 0? And then set it to the previous value to turn it on?

To set the volume of all the music files (Mix_Music* pMusicFile) in your project, you can use ‘Mix_VolumeMusic()’.

To set the volume of the sound files (Mix_Chunk* pSoundFile) in your project, you can use ‘Mix_Volume()’. If you specify the channel argument as ‘-1’, you’ll set the volume for all the channels.

Naith wrote:

To set the volume of all the music files (Mix_Music* pMusicFile) in your project, you can use ‘Mix_VolumeMusic()’.

To set the volume of the sound files (Mix_Chunk* pSoundFile) in your project, you can use ‘Mix_Volume()’. If you specify the channel argument as ‘-1’, you’ll set the volume for all the channels.

Ho crap, I missed that in the documentation.
Thanks!

You’re welcome. :slight_smile:

I want ot add a sound on/off button to my game. I’ve looked thru the
SDL_Mixer API and I haven’t seen any function that toggle sound on/off
(globally).
Do I have to keep track of all sounds that are playing (and music) and set
volume to 0? And then set it to the previous value to turn it on?

To pause music and samples:

    Mix_Pause(-1);
    Mix_PauseMusic();

To resume:

    Mix_Resume(-1);
    Mix_ResumeMusic();On Mon, Aug 11, 2014 at 1:02 PM, Limanima <jorge.raposo.lima at gmail.com> wrote:


Bye,
Gabry