muting sounds for all scenes

Hi,

I am working on a simple game using Corona SDK, that consists of two scenes : a main menu and the game play scene. 

I have added a button for muting all sounds and  music in the game to the main menu scene.  The issue I am having is that when I click on the sound off button it only mutes the sounds from the main menu  and not from the game play scene,

How can I keep all sounds and music muted for all scenes.

Thank you

Hi @hsheikh140,

Are you specifying a channel when you handle your “sound off” button? If so, you should omit that… using “audio.setVolume( 0 )” controls all channels and it will effectively control all sounds and music.

https://docs.coronalabs.com/api/library/audio/setVolume.html

Take care,

Brent

Hi Brent ,

Thank you for your reply , let me give you a little more info on my project.   I have 3 lua files: main.lua , scene_menu.lua and scene_game.lua. 

I have loaded all the sounds and back ground music in main.lua as follows:

_BACKGROUNDMUSIC = audio.loadStream (“backgroundB.mp3”)

   _HIT= audio.loadSound(“blast.mp3”)

   _KILL = audio.loadSound(“boing-1.wav”)

   _POP= audio.loadSound(“burst.wav”)

   _CLICK= audio.loadSound(“click.mp3”)

   _FLAPPING = audio.loadSound(“Flapping.wav”)

scene_menu.lua   is the main menu screen for my game. I have  created a widget button to mute all sounds and music in the game on this screen as follows:

local function onSoundsTouch(event)

    if(event.phase == “ended” ) then 

            – mute the game

           audio.setVolume(0)

       

    else 

        – unmute the game

             audio.setVolume(1)

           end

    end

btn_sounds = widget.newButton {

            width = 50,

            height = 50,

            defaultFile = “SoundOff.png”,

            overFile = “SoundOff_Overlay.png”,

            onEvent = onSoundsTouch

            }

            btn_sounds.x = _R - 25

            btn_sounds.y = _B - 25

            sceneGroup: insert(btn_sounds)

I am able to mute the sounds on the main menu however once i start the game , the music and sounds all resume. How can i make sure that when the sound off button is pressed on the menu screen all sounds and music stay muted when the player starts the game.

Hi,

You might find some tips in here.

https://codeponies.wordpress.com/2013/12/02/lets-create-a-corona-sdk-soundtrack-module-part-1/

Cheers

Thank you develephant I was able to solve the issue using the guide you posted.

Hi @hsheikh140,

Are you specifying a channel when you handle your “sound off” button? If so, you should omit that… using “audio.setVolume( 0 )” controls all channels and it will effectively control all sounds and music.

https://docs.coronalabs.com/api/library/audio/setVolume.html

Take care,

Brent

Hi Brent ,

Thank you for your reply , let me give you a little more info on my project.   I have 3 lua files: main.lua , scene_menu.lua and scene_game.lua. 

I have loaded all the sounds and back ground music in main.lua as follows:

_BACKGROUNDMUSIC = audio.loadStream (“backgroundB.mp3”)

   _HIT= audio.loadSound(“blast.mp3”)

   _KILL = audio.loadSound(“boing-1.wav”)

   _POP= audio.loadSound(“burst.wav”)

   _CLICK= audio.loadSound(“click.mp3”)

   _FLAPPING = audio.loadSound(“Flapping.wav”)

scene_menu.lua   is the main menu screen for my game. I have  created a widget button to mute all sounds and music in the game on this screen as follows:

local function onSoundsTouch(event)

    if(event.phase == “ended” ) then 

            – mute the game

           audio.setVolume(0)

       

    else 

        – unmute the game

             audio.setVolume(1)

           end

    end

btn_sounds = widget.newButton {

            width = 50,

            height = 50,

            defaultFile = “SoundOff.png”,

            overFile = “SoundOff_Overlay.png”,

            onEvent = onSoundsTouch

            }

            btn_sounds.x = _R - 25

            btn_sounds.y = _B - 25

            sceneGroup: insert(btn_sounds)

I am able to mute the sounds on the main menu however once i start the game , the music and sounds all resume. How can i make sure that when the sound off button is pressed on the menu screen all sounds and music stay muted when the player starts the game.

Hi,

You might find some tips in here.

https://codeponies.wordpress.com/2013/12/02/lets-create-a-corona-sdk-soundtrack-module-part-1/

Cheers

Thank you develephant I was able to solve the issue using the guide you posted.