Mute btn

How is the best way to mute EVERYTHING in my game. I want to have a speaker button that will mute all sounds whenever it is pushed.

Much appreciated,
J.K. [import]uid: 66117 topic_id: 18727 reply_id: 318727[/import]

Did you ever seen Corona SDK API? http://developer.anscamobile.com/resources/apis
Really nasty stuff! You can find here things like this:
[lua] audio.setVolume( 0 ) – set the master volume
audio.setVolume( 0, { channel=1 } ) – set the volume on channel 1[/lua]

or (if you hold sound and music in old fashion style)
[lua] media.setSoundVolume( 0 )[/lua]

And lots more goodies like this!

[import]uid: 12704 topic_id: 18727 reply_id: 71964[/import]

gtartarkin,

Yes, I have referred the Corona SDK APIs several times. I have tried using the code found there, but it still doesn’t work. It will mute the MUSIC, as in audio.loadStream. But it doesn’t mute SOUND, as in media.playEventSound. [import]uid: 66117 topic_id: 18727 reply_id: 71974[/import]

Anybody else have an idea? [import]uid: 66117 topic_id: 18727 reply_id: 72014[/import]

Did you try
    media.setSoundVolume( 0 )
nil and dispose your sound file and handlers? [import]uid: 12704 topic_id: 18727 reply_id: 72022[/import]

Well, I don’t see how that would work. I have buttons in my game. Whenever the button is pushed a sound is played. If the button in the main menu is pressed to mute the sound, how is it going to nil out and dispose those sounds? Also, I want to be able to turn the audio back on by pushing the same button. [import]uid: 66117 topic_id: 18727 reply_id: 72029[/import]

Okay, that was weird. Why did it post it twice? [import]uid: 66117 topic_id: 18727 reply_id: 72031[/import]

I deleted the second post. From time to time that happens, I’m not sure why :wink:

For the sound, you need to try things before deciding they wont work.

In this case that should work fine - however you should be playing the sounds using the new method and then by using audio.setVolume(0) all sounds will be muted.

If you need to keep using the old method for some reason then use both audio.setVolume(0) and media.setSoundVolume(0) as gtatarkin advised.

Peach :slight_smile: [import]uid: 52491 topic_id: 18727 reply_id: 72057[/import]

@Peach,

I looked at the “new” way of doing it with audio.loadStream. How would I play it? With the usual audio.play()?

As for the old way, this is what I have:
[lua]–In the main.lua file–
audio.setVolume(0)
media.setSoundVolume(0)
–In the menu.lua file–
backgroundMusicChannel = audio.play(backgroundMusic, {channel=1, loops=-1})–In game.lua file–
if e.target.myName == “blue” then
blueRadiate.x = e.x; blueRadiate.y = e.y; blueRadiate.alpha = 1
transition.to(blueRadiate, {1000, xScale = 1.5, yScale = 1.5, alpha = 0, onComplete=reTweenBlue })
media.playEventSound (goodTap) blue.alpha = 1
blueOn = true
blueBtnTime = math.random(3,5)
blueBtnTmr.text = blueBtnTime
bluetmr = timer.performWithDelay(1000, blueTimer, blueBtnTime)
blueTimeUp = false
audio.dispose(buttonSound)
end[/lua]
Not quite sure what the deal is. I will try the new way and see if that works.

[import]uid: 66117 topic_id: 18727 reply_id: 72081[/import]

Okay, got it figured out. Thank both of you for your time and patience. I am NOW using the new way to do sounds. The only question I have is does it play the sound, then free up the channel it was played on? The API said, “laserChannel = audio.play( laserSound ) – play the laser on any available channel.” Does that mean I have to go in and manually free up the channel? [import]uid: 66117 topic_id: 18727 reply_id: 72088[/import]

Oh, nvrmnd. I figured it out. Thank you Gutararkin and Peach.

Very much appreciated,
J.K. [import]uid: 66117 topic_id: 18727 reply_id: 72091[/import]

Glad you got it sorted; the new audio way is much better once you’ve figured it out :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 18727 reply_id: 72138[/import]