SFX and MUSIC on/off buttons

Hi guys

I have a good idea on how to load and play sounds using Corona.

However, I can’t figure out how I would go about having a sfx on/off button, that turns off all the sound effects in the game but not the music - then also a button for music that turn off the music but not the sfx.

If anybody has done this before or knows of any tutorials detailing the process, that would be awesome!

I’ve had a look around, but can’t seem to find the right info.

Thank you in advance for any help :slight_smile:

Use the media.pause function to your advantage here :3 You could easily make one of these by making a widget.button and making your custom button skin. Then, pin your media.pause function to that button an whala!

The way I do this is I have a setting in my settings table that I have available in all my modules:

mySettings.soundOn = true

mySettings.musicOn = true

Then when I go to play my sound effects, I do:

if mySettings.soundOn then

     audio.play(…)

end

I offer a settings screen with on/off buttons for Sound and Music that sets the values of those two settings.  If music is playing and it gets turned off, I then stop it.  If it gets turned on, then I can either start it or wait to the scene that needs to play the music starts it.

Music is a bit trickier, since it tends to play longer, so you need to stop it and resume it when people change the settings.

Rob

Hi guys

Thank you for your help on this :slight_smile:

I’m just wondering whether there is some sort of way to tag or group sounds, so I can the set the volume to 0 for the whole group instead of pausing/switching them off?

If you’re using the audio.* library, you can always set the master volume to 0 and I think audio.stop() has a way to kill all audio.  The media.* library doesn’t have those features that I’m aware of.

Rob

Hi guys

Thank you very much for your help! I tried searching some info on the audio library and stumbled across a topic which describes exactly what I was looking for :slight_smile:

http://forums.coronalabs.com/topic/39231-sound-fx-volume-and-music-volume/

Thank you again!

Use the media.pause function to your advantage here :3 You could easily make one of these by making a widget.button and making your custom button skin. Then, pin your media.pause function to that button an whala!

The way I do this is I have a setting in my settings table that I have available in all my modules:

mySettings.soundOn = true

mySettings.musicOn = true

Then when I go to play my sound effects, I do:

if mySettings.soundOn then

     audio.play(…)

end

I offer a settings screen with on/off buttons for Sound and Music that sets the values of those two settings.  If music is playing and it gets turned off, I then stop it.  If it gets turned on, then I can either start it or wait to the scene that needs to play the music starts it.

Music is a bit trickier, since it tends to play longer, so you need to stop it and resume it when people change the settings.

Rob

Hi guys

Thank you for your help on this :slight_smile:

I’m just wondering whether there is some sort of way to tag or group sounds, so I can the set the volume to 0 for the whole group instead of pausing/switching them off?

If you’re using the audio.* library, you can always set the master volume to 0 and I think audio.stop() has a way to kill all audio.  The media.* library doesn’t have those features that I’m aware of.

Rob

Hi guys

Thank you very much for your help! I tried searching some info on the audio library and stumbled across a topic which describes exactly what I was looking for :slight_smile:

http://forums.coronalabs.com/topic/39231-sound-fx-volume-and-music-volume/

Thank you again!