This seems to be so easy, but I’m stuck here.
What I want to accomplish is a seperate On/Off state for both Music and Sound. The user should be able to switch it ingame.
Right now it works on the simulator, but not on the actual device (iPad). It’s probably a bug as other users have mentioned on the API page.
http://developer.coronalabs.com/reference/index/audiosetvolume
I’ve read similar topics and mostly the solution was an if statement before every audio.play but that’s over the top.
[code]
local isMusicOn = true
audio.reserveChannels( 2 ) – reserve channels 1 and 2 for music only
local music_channel = audio.loadStream(“bg.mp3”) – 3 min background music
local swoshSound = audio.loadSound(“swosh.caf”) – 1s Sound
bg_music = audio.play( music_channel, { channel=1, loops=-1, fadein=5000 } )
timer.performWithDelay( 1000, function () audio.play(swoshSound) end , 0 ) – loop sound for testing
local function sound_switch(state)
if state == “off” then
print(“sound off”)
audio.setMaxVolume( 0 ) – mute all channels
if isMusicOn == true then
audio.setMaxVolume( 1, { channel=1 } ) – keeps music on
audio.setVolume( 1, { channel= 1 } )
end
else
audio.setMaxVolume( 1 )
audio.setVolume( 1)
print(“sound on”)
end
end
local function music_switch(state)
if state == “off” then
print(“music off”)
audio.setVolume( 0, { channel= 1 } ) --mute only music channel
isMusicOn = false
else
isMusicOn = true
audio.setMaxVolume( 1, { channel=1 } ) – keeps music on
audio.setVolume( 1, { channel= 1 } )
print(“music on”)
end
end
– … more code, irrelevant for support …
[/code] [import]uid: 98393 topic_id: 29145 reply_id: 329145[/import]

