Device audio control is disabled within game - please re-enable system audio controls...

I got the following feedback for my Android app:

“Device audio control is disabled within game - please re-enable system audio controls.”

Does this have to do with using this key event code in main.lua?

\_G.onKeyEvent = function( event ) &nbsp;&nbsp; local phase = event.phase &nbsp;&nbsp; local keyName = event.keyName &nbsp;&nbsp; local lastScene=\_G.returnTo &nbsp;&nbsp; if ( keyName == "volumeUp" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print( "volume:", masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( masterVolume \< 1.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; masterVolume = masterVolume + 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true &nbsp;&nbsp; elseif ( keyName == "volumeDown" and phase == "down" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local masterVolume = audio.getVolume() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print( "volume:", masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( masterVolume \> 0.0 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; masterVolume = masterVolume - 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.setVolume( masterVolume ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true &nbsp;&nbsp; end &nbsp;&nbsp; return false&nbsp; --SEE NOTE BELOW end Runtime:addEventListener( "key", \_G.onKeyEvent )

What can I do to fix this?

Help welcome!

Hey c.noeth,

I think your specultion is correct.

As you return true when the volume Buttons are pressed the system won’t recieve those events.

Therefor there is no interface showing the player the volume has changed (as coronas volume is different from the device volume).

So there are two options for you.

  1. Building your own volume interface that is displayed when the user changes the volume.

  2. Don’t block the user from changing his devices mastervolume and instead offer an interface element inside your app (in the options screen) that allows the player to change the volume manually.

Hi c.noeth,

Not sure how to say it than to just say it; using _G is highly frowned upon in Lua. And especially when Lua is used as a scripting layer for a larger framework like Corona SDK. It may be easy, but it will only cause you trouble.

Using a Lua module is best practice for “global” functionality. As a quick visual (untested):

[lua]

– simple sound_mod.lua

local audio = require( ‘audio’ )

local snd = {

  cached_vol = audio.getVolume()

}

function snd:getVolume()

  return audio.getVolume()

end

function snd:setVolume( vol_num )

  if not self:isSaneVolume( vol_num ) then

    return --do nothing, out of bounds

  end

  audio.setVolume( vol_num )

end

function snd:incVolume( amt )

  local amt = self:getVolume() + amt

  self:setVolume( amt )

end

function snd:decVolume( amt )

  local amt = self:getVolume() - amt

  self:setVolume( amt )

end

function snd:muteVolume( mute_bool )

  if mute_bool == true then

    self.cached_vol = audio.getVolume()

    self:setVolume( 0 )

  else

    self:setVolume( self.cached_vol )

  end

end

function snd:isMuted()

  if self:getVolume() == 0 then

    return true

  end

  return false

end

function snd:isSaneVolume( vol )

  if ( vol < 0 ) or ( vol > 1 )  then

    return false – out of bounds

  end

  return true

end

return snd

[/lua]

And then you load this module in your main.lua, as well as any other place it is needed.

[lua]

– main.lua

local snd_mod = require(‘sound_mod’)

–==============================================================–

–== Usage Examples

–==============================================================–

– Get

local vol = snd_mod:getVolume()

– Set

snd_mod:setVolume( num )

– Increase

snd_mod:incVolume( amt )

– Decrease

snd_mod:decVolume( amt )

– Mute

snd_mod:muteVolume( true )

– UnMute

snd_mod:muteVolume( false )

– is Muted?

local is_muted = snd_mod:isMuted()

[/lua]

I’m not saying that this will fix your particular issue, but is something that is very important for all Corona developers to understand.

Cheers.

Hey c.noeth,

I think your specultion is correct.

As you return true when the volume Buttons are pressed the system won’t recieve those events.

Therefor there is no interface showing the player the volume has changed (as coronas volume is different from the device volume).

So there are two options for you.

  1. Building your own volume interface that is displayed when the user changes the volume.

  2. Don’t block the user from changing his devices mastervolume and instead offer an interface element inside your app (in the options screen) that allows the player to change the volume manually.

Hi c.noeth,

Not sure how to say it than to just say it; using _G is highly frowned upon in Lua. And especially when Lua is used as a scripting layer for a larger framework like Corona SDK. It may be easy, but it will only cause you trouble.

Using a Lua module is best practice for “global” functionality. As a quick visual (untested):

[lua]

– simple sound_mod.lua

local audio = require( ‘audio’ )

local snd = {

  cached_vol = audio.getVolume()

}

function snd:getVolume()

  return audio.getVolume()

end

function snd:setVolume( vol_num )

  if not self:isSaneVolume( vol_num ) then

    return --do nothing, out of bounds

  end

  audio.setVolume( vol_num )

end

function snd:incVolume( amt )

  local amt = self:getVolume() + amt

  self:setVolume( amt )

end

function snd:decVolume( amt )

  local amt = self:getVolume() - amt

  self:setVolume( amt )

end

function snd:muteVolume( mute_bool )

  if mute_bool == true then

    self.cached_vol = audio.getVolume()

    self:setVolume( 0 )

  else

    self:setVolume( self.cached_vol )

  end

end

function snd:isMuted()

  if self:getVolume() == 0 then

    return true

  end

  return false

end

function snd:isSaneVolume( vol )

  if ( vol < 0 ) or ( vol > 1 )  then

    return false – out of bounds

  end

  return true

end

return snd

[/lua]

And then you load this module in your main.lua, as well as any other place it is needed.

[lua]

– main.lua

local snd_mod = require(‘sound_mod’)

–==============================================================–

–== Usage Examples

–==============================================================–

– Get

local vol = snd_mod:getVolume()

– Set

snd_mod:setVolume( num )

– Increase

snd_mod:incVolume( amt )

– Decrease

snd_mod:decVolume( amt )

– Mute

snd_mod:muteVolume( true )

– UnMute

snd_mod:muteVolume( false )

– is Muted?

local is_muted = snd_mod:isMuted()

[/lua]

I’m not saying that this will fix your particular issue, but is something that is very important for all Corona developers to understand.

Cheers.