Keeping my app muted

My app only has two screens: the main screen and a settings screen. The mute button I have is on the main screen, and when it is pressed the image changes so that you know it’s muted. The problem is, if I touch the mute button, go to the settings menu, then come back it is unmated. How do I gets around this? Thanks

Nathan [import]uid: 39302 topic_id: 23575 reply_id: 323575[/import]

Hi!

You will have to post your code below to assist us!

Please enclose them in the provided < lua > and < /lua > tags. [import]uid: 10389 topic_id: 23575 reply_id: 94604[/import]

Okay. Here’s my main.lua…

[lua]display.setStatusBar(display.DarkStatusBar)

local director = require(“director”)

local mainGroup = display.newGroup()

local function main()
mainGroup:insert(director.directorView)

W = display.contentWidth
H = display.contentHeight

director:changeScene(“Main”)

return true

end

main()[/lua]

here’s the mute button stuff…

[lua] --**MUTE BUTTON FUNCTIONS**–==================================

local mutebuttonfunction = function (event )
if event.phase == “release” then
audio.setVolume( 0, { channel=0 } )
print “Muted”
end
end

local unmutebuttonfunction = function (event )
if event.phase == “release” then
audio.setVolume( 0.1, { channel=0 } )
print “Unmuted”
end
end

–**MUTE BUTTONS**–=====================

local mutebutton = widget.newButton{
default = “soundon.png”,
over = “soundonD.png”,
width = 35,
height = 66,
onRelease = mutebuttonfunction,
}

mutebutton.isVisible = true

mutebutton.x = display.contentWidth / 12
mutebutton.y = display.contentHeight / 1.074

localGroup:insert(mutebutton.view)

local unmutebutton = widget.newButton{
default = “soundoff.png”,
over = “soundoffD.png”,
width = 35,
height = 66,
onRelease = unmutebuttonfunction,
}

unmutebutton.isVisible = false

unmutebutton.x = display.contentWidth / 12
unmutebutton.y = display.contentHeight / 1.074

localGroup:insert(unmutebutton.view)

–**MUTE BUTTON SWITCHING**–===================================

local unmutebuttonappear = function(event)
if event.phase == “ended” then
mutebutton.isVisible = false
unmutebutton.isVisible = true
end
end

mutebutton:addEventListener(“touch”, unmutebuttonappear)

local mutebuttonappear = function(event)
if event.phase == “ended” then
mutebutton.isVisible = true
unmutebutton.isVisible = false
end
end

unmutebutton:addEventListener(“touch”, mutebuttonappear)
[/lua]

This is the function for the button that switches to the setting screen I mentioned above…

[lua]–**SETTINGS BUTTON FUNCTIONS**======================

local settingsbuttonfunction = function (event )
if event.phase == “release” then
Runtime:removeEventListener( “enterFrame”, animate)
audio.stop( fannoise )
director:changeScene(“settingsmenu”, “moveFromRight”)
print “Settings menu”
end
end[/lua]
I think that’s all the stuff that matter. Let me know if it’s not. Thank you. [import]uid: 39302 topic_id: 23575 reply_id: 94616[/import]

Is the sound actually muted when you try to play a tune or make noise?

I think the problem is the volume does get muted, but when you go to the Settings screen, the buttons are always set as ON.
There’s no global variable to store the state of the mute.

Eg.

mute = true

Then, when you display the settings screen, you have to manually check this variable and change the image to pressed or not-pressed by yourself.
The buttons do not have a memory of their own so will go to whatever state you set them to initially. [import]uid: 10389 topic_id: 23575 reply_id: 94639[/import]

Alternatively, use audio.getVolume()

This is probably better than keeping a global variable, but you cannot easily save this state when exiting the app. [import]uid: 10389 topic_id: 23575 reply_id: 94640[/import]

Is there a doc or something I could read? If not, I’ll need some help…
I really appreciate your time. :slight_smile: [import]uid: 39302 topic_id: 23575 reply_id: 94969[/import]

What is the difference between audio.setVolume and audio.getVolume? [import]uid: 39302 topic_id: 23575 reply_id: 96912[/import]

One gets you the current volume and the other one sets it to a value you specify… [import]uid: 10389 topic_id: 23575 reply_id: 97211[/import]