Not sure what my problem is here but I’ve had a LOT of Android users complain that the audio is not working correctly in my app - specifically using the hardware buttons to control the audio doesn’t seem to work.
I’m using the audio.load / .play functions and they seem to work correctly on iOS, I’m also setting the min and max volumes like so
audio.setMinVolume(0); audio.setMaxVolume(1); for i=1,32 do audio.setVolume(1,{channel = i}) end; audio.setVolume( 1 )
at the start of my app.
I added the following code to detect / respond to the hardware buttons (and show a volume slider on the screen)
local volumeUp, volumeDown = "volumeUp", "volumeDown" if \_TARGET\_ENVIRONMENT == "SIMULATOR" then volumeUp, volumeDown = "up","down" end local volumeGroup, volumeButton, volumeFade = nil,nil, false local adjustmentDelta, lastPhase, keyRepeater local function showVolumeGroup(volume) local width = \_W \* 0.75 local left = \_CX - (width / 2) if volumeGroup == nil then volumeGroup = display.newGroup() local bar = display.newRoundedRect(volumeGroup, \_CX, \_CY, width, 8, 2) bar.strokeWidth = 2 bar:setFillColor(0.98,0.92,0.84) bar:setStrokeColor(0) volumeButton = wtf.image({parent=volumeGroup, asset="volume\_button",xScale=1.25,yScale=1.25}) -- ,tint={0.25,1,0.25}}) end volumeButton.x = left + (volume \* width) if volumeFade then transition.cancel(volumeGroup) end volumeGroup.alpha = 1; volumeFade = true transition.to(volumeGroup,{alpha=0,time=250,delay=500,onComplete=function() volumeFade=false end}) end local function adjustvolume(delta) local masterVolume = audio.getVolume(); -- print( "volume:", masterVolume ) masterVolume = masterVolume + delta if masterVolume \< 0 then masterVolume = 0 elseif masterVolume \> 1 then masterVolume = 1 end audio.setVolume(masterVolume) showVolumeGroup(masterVolume) audio.play(NOTE\_SAMPLES.C4) timer.performWithDelay(200,function() if keyRepeater then adjustvolume(delta) end end) end function ON\_KEY\_EVENT( event ) local phase = event.phase local keyName = event.keyName -- ------------------------------------------------------- -- Have this work an on screen volume slider... if phase == "up" then adjustmentDelta, lastPhase, keyRepeater = 0,phase,false elseif phase == "down" then if lastPhase ~= "down" then if keyName == volumeUp then adjustmentDelta, lastPhase, keyRepeater = 0.05,phase,true elseif keyName == volumeDown then adjustmentDelta, lastPhase, keyRepeater = -0.05,phase,true end if keyRepeater then adjustvolume(adjustmentDelta) end end end return true end
Whilst this DOES respond to key events (and the slider works) it sounds like the audio range goes from silent to the currently set system master volume - if I set the master volume to full outside of my app then the volume works as expected, but if I set the system master volume to 50% then that’s the max range inside the app.
I’ve seen other Android / Kindle Corona apps that appear to work correctly and actually set the device master volume but for the life of me I can’t work out how they do it.
On a related note ( I know this is a daft question but…) I get a fair number of users on iOS who complain that they can’t hear any audio and it turns out that the mute button on the side of the device is turned on - again I’m sure I’ve seen other apps that ignore this setting and can play audio regardless.
Any help would be gratefully appreciated.

