Audio On/Off button on main menu

Hi,

I am new to Corona and have been experimenting with this for less than a few months.

I am attempting to find a solution to allow me to add a on/off sound option to a storyboard based app.

I found myself watching this video which I thought may help:

http://www.infiniteskills.com/training/mobile-game-development-with-corona-sdk/playing-music-in-your-app.html

I’ve tried to follow his guidance but seem to get stuck with the following code (which is really basic):

local bgmusic = audio.loadStream(‘bgmusic.wav’)
local bgmusicplay = true

function playsound()
    if bgmusicplay then
        audio.play(bgmusic, { channel=1, loops=-1,   fadein   =500 })
    end
end

I keep looking at this code but can’t seem to get my head around the problem. There are other parts of the code which involves adding buttons to play the sound or stop the sound but thats no necessary as yet.

I am using a public storyboard template to experiment with Corona SDK and programming itself and this code is placed as part of the start.lua.

If you need more information so as to provide me with guidance please ask.

Does “On/Off sound option” mean you want to allow the ability to “Mute” all sounds?

Or do you mean add the ability for the user to “Stop” just the background music?

If it’s the 2nd, in addition to the code you already have above, you can add an image or add some Text such as “Mute Music” to the screen.

muteMusicText = display.newText(“Mute Music”, 100, 100, “Times”, 20)

Then make a function and an event listener like this which stops the music in Channel 1:

function muteSound (event)

audio.stop (1)

end

muteMusicText:addEventListener( “tap”, muteSound )

Does “On/Off sound option” mean you want to allow the ability to “Mute” all sounds?

Or do you mean add the ability for the user to “Stop” just the background music?

If it’s the 2nd, in addition to the code you already have above, you can add an image or add some Text such as “Mute Music” to the screen.

muteMusicText = display.newText(“Mute Music”, 100, 100, “Times”, 20)

Then make a function and an event listener like this which stops the music in Channel 1:

function muteSound (event)

audio.stop (1)

end

muteMusicText:addEventListener( “tap”, muteSound )