media.capturePhoto Doesn't Run Its Listener

Hi all,
I want in my code that the user will take a picture using media.capturePhoto, and then a listener will handle the photo, but for some reason it doesn’t go to the handler (it just opens the camera and let the user take a picture, but then just go back to the screen without doing anything). Nevertheless, I also have a media.selectPhoto function, and after the user selects a photo it DOES runs the handler, so I know the handler works…
 
Here’s my code - 
 (NOTE: in my settings file I do have the permission to use the camera)

 storyboard = require ("storyboard") scene = storyboard.newScene() function scene:createScene(event) end function scene:enterScene(event) centerX = display.contentCenterX centerY = display.contentCenterY width = display.contentWidth height = display.contentHeight mainGroup = display.newGroup( ) selectBtn = display.newText(mainGroup, "Select", centerX, centerY, native.systemFont, 128) takePicButton = display.newText(mainGroup, "Capture Photo", centerX, centerY+200, native.systemFont, 100) function savePic(event) test = event.target if (test) then print("event completed") wantedHeight = (width/test.width)\*test.height test.height, test.width = wantedHeight, width test.x,test.y = centerX, centerY mainGroup:insert( test ) mainGroup:insert(event.target) loadingText:toFront( ) timer.performWithDelay( 1, function ( ) display.save( test, { filename="original.png", baseDir=system.DocumentsDirectory}) storyboard.gotoScene( "crop" ) end) end end function capture(event) if media.hasSource( media.Camera ) then media.capturePhoto( {listener = savePic} ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end end function select( event ) if (event.phase == "ended") then if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource = media.PhotoLibrary, listener = savePic } ) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end end end selectBtn:addEventListener("touch", select) takePicButton:addEventListener("touch", capture) end function scene:exitScene(event) takePicButton:removeEventListener("touch", capture) selectBtn:removeEventListener("touch", select) mainGroup:removeSelf( ) mainGroup = nil end function scene:destroyScene(checkMemory) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene

Does anyone knows what’s wrong with my code?

Thanks, Dan

Hi Dan,

I’m concerned that you’re using a “touch” handler on the takePicButton. This means that you’re sending potentially dozens of requests to that listener, since it’s detecting began, moved, and ended. Please switch this to a “tap” handler and see if that helps.

Best regards,

Brent

Hi Dan,

I’m concerned that you’re using a “touch” handler on the takePicButton. This means that you’re sending potentially dozens of requests to that listener, since it’s detecting began, moved, and ended. Please switch this to a “tap” handler and see if that helps.

Best regards,

Brent