Audio toggle developed in code not working on device

my app Eagle Screech! is out on Amazon, Google Play and iTunes right now, so you can test the below. I have music and sound effects loaded with the loadStream function. I set a simple toggle in the options screen to set the volume in-code for the channels I used for music, and for sound effects. Toggle on, the level is set to a certain volume; toggle off, and it sets it to zero.

It works perfectly on an Android which is my main device (it really shouldn’t be, but whatever) but as soon as I started testing on iOS devices, the volume would not change via the in-game toggle. The toggle works normally on both Windows and Mac simulators, as well as Android. I tested it on several different devices with both Android and iOS, and the issue only appears on iOS devices. I tested it on iOS devices with both iOS 6 and 5.1.1 installed.

I tested it with both loadSteam and loadSound, and the problem persists. The offending code (I believe) for my music.lua file is below. Please let me know if I can provide any additional data. As I said, the bug can be found in the released version of the app, which can be downloaded on Amazon, Google Play and iTunes. Thanks!

[lua]local function turnOffEffects()
for i=1, 28 do
if GameSettings.SoundOn == false then
audio.setMaxVolume( 0, { channel=4+(i*1) } )
end
end
end

local function turnOnEffects()
for i=1, 28 do
if GameSettings.SoundOn == true then
audio.setMaxVolume( .7, { channel=4+(i*1) } )
end
end
end

local function turnOffMusic()
for i=1, 4 do
if GameSettings.MusicOn == false then
audio.setMaxVolume( 0, { channel=0+(i*1) } )
end
end
end

local function turnOnMusic()
for i=1, 4 do
if GameSettings.MusicOn == true then
audio.setMaxVolume( .7, { channel=0+(i*1) } )
end
end
end[/lua] [import]uid: 135394 topic_id: 33816 reply_id: 333816[/import]

I just guessing here but audio.setMaxVolume() isn’t designed to set the volume on the channel, just set the limits. If you set it to 0, then back to .7, the actual volume hasn’t changed because you are not calling audio.setVolume(). Try using audio.setVolume() and see if that makes a difference.

As a side note:

for i=1, 28 do  
if GameSettings.SoundOn == false then  
audio.setMaxVolume( 0, { channel=4+(i\*1) } )  
 end  
 end  
end  

might be easier if you did:

for i=5, 32 do if GameSettings.SoundOn == false then audio.setMaxVolume( 0, { channel=i } ) end end end [import]uid: 199310 topic_id: 33816 reply_id: 134415[/import]

Rob, I’ll definitely be testing your suggestions tonight. It’s weird that it works as coded on Android and both simulators, but not in practice on iOS devices. I’ll update here after testing. [import]uid: 135394 topic_id: 33816 reply_id: 134439[/import]

Rob is correct, audio.setMaxVolume() does not actually set the volume on those channels, it only caps the “potential value” that the sound might reach in the future. You should use the audio.setVolume() API in your loop(s).

Also, if you use Rob’s second example with the loop going from 5 to 32 (the total number of channels), you might want to be “safe” and specify audio.totalChannels instead of 32. If Corona decides to increase the total channels to 64 in the future, you’ll be covered by specifying to total available channels in the current version of Corona.

Brent
[import]uid: 200026 topic_id: 33816 reply_id: 134444[/import]

@Brent and @Rob, thanks for the suggestions! That solved the problem. I guess I should have posted in the developer forum first, but since my previous code worked on Android and both simulators, I assumed it was a bug. Thanks again! [import]uid: 135394 topic_id: 33816 reply_id: 134481[/import]

I just guessing here but audio.setMaxVolume() isn’t designed to set the volume on the channel, just set the limits. If you set it to 0, then back to .7, the actual volume hasn’t changed because you are not calling audio.setVolume(). Try using audio.setVolume() and see if that makes a difference.

As a side note:

for i=1, 28 do  
if GameSettings.SoundOn == false then  
audio.setMaxVolume( 0, { channel=4+(i\*1) } )  
 end  
 end  
end  

might be easier if you did:

for i=5, 32 do if GameSettings.SoundOn == false then audio.setMaxVolume( 0, { channel=i } ) end end end [import]uid: 199310 topic_id: 33816 reply_id: 134415[/import]

Rob, I’ll definitely be testing your suggestions tonight. It’s weird that it works as coded on Android and both simulators, but not in practice on iOS devices. I’ll update here after testing. [import]uid: 135394 topic_id: 33816 reply_id: 134439[/import]

Rob is correct, audio.setMaxVolume() does not actually set the volume on those channels, it only caps the “potential value” that the sound might reach in the future. You should use the audio.setVolume() API in your loop(s).

Also, if you use Rob’s second example with the loop going from 5 to 32 (the total number of channels), you might want to be “safe” and specify audio.totalChannels instead of 32. If Corona decides to increase the total channels to 64 in the future, you’ll be covered by specifying to total available channels in the current version of Corona.

Brent
[import]uid: 200026 topic_id: 33816 reply_id: 134444[/import]

@Brent and @Rob, thanks for the suggestions! That solved the problem. I guess I should have posted in the developer forum first, but since my previous code worked on Android and both simulators, I assumed it was a bug. Thanks again! [import]uid: 135394 topic_id: 33816 reply_id: 134481[/import]