media.capturePhoto does not call event Listener.

I want to use camera on Android 4.3.

I tried Nexus 7 and XPERIA SO01F .

I set “usesPermissions” as below on build.settings.

 android = { usesPermissions = { "android.permission.INTERNET", "android.permission.CAMERA", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, },

I wrote codes as below.

if media.hasSource( media.Camera ) then media.capturePhoto( { listener = sessionComplete , destination = { baseDir=system.TemporaryDirectory, filename="sc.jpg", type="image" } } ) else native.showAlert("Corona", "Camera not found.") end

When this code is executed, the camera is activated.

When I take a picture, the camera automatically closes. 

But “onComplete” was not called.

Is it bug ?

Hi @Naofumi,

Is your “sessionComplete” function in the proper scope? Can you post how that function looks?

Thanks,

Brent

Hi Brent,

Thank you for your replay.

“sessionComplete” function is as below.

local sessionComplete = function(event) print('go to editing scenes') composer.gotoScene('scenes.edit') end

Scene was not change.

I checked logs, but “go to editing scenes” was not output…

By the way, I’m Enterprise licensed user, 

but my license is displayed “Pro”.

Why…?

Thanks, and is that function in the proper Lua scope?

Yes, Hrea is the code.

local sessionComplete = function(event) print('go to editing scenes') composer.gotoScene('scenes.edit') end if media.hasSource( media.Camera ) then media.capturePhoto( { listener = sessionComplete , destination = { baseDir=system.TemporaryDirectory, filename="sc.jpg", type="image" } } ) else native.showAlert("Corona", "Camera not found.") end

I can get event when took a picture on simulator.

What I’m seeing is that media.capturePhoto will fail to return correctly if the file you are trying to save to does not already exist. It seems like it’s trying to delete the old file, before saving the new one, but if the file does’t exist you get an error.

I also see this in the simulator. Try removing the file sc.jpg and run the code in the simulator and see if it gives you an error message on the first run.

I tried to remove “sc.jpg”, but “onComplete” was not called.

 if system.getInfo('platformName') ~= 'iPhone OS' and event.target.id=='camera' then local sessionComplete = function(event) local image = event.target if image then display.save( image,'sc.jpg',system.TemporaryDirectory) composer.gotoScene('scenes.edit') display.remove(image) end end if media.hasSource( media.Camera ) then os.remove( system.pathForFile( "sc.jpg" ,system.TemporaryDirectory) ) media.capturePhoto( { listener = sessionComplete , destination = {baseDir=system.TemporaryDirectory, filename="sc.jpg", type="image"} } ) else native.showAlert("Corona", "Camera not found.") end else composer.gotoScene('scenes.'..event.target.id,{effect='fade',time=200}) end

Hi Naofumi Ozawa

Try this code.

This code work fine for me.

local function onComplete(event)

   local photo = event.target

   print( “onComplete called …” )

    local img = display.newImageRect(“image.jpg”,system.TemporaryDirectory,200,200)

    img.x = 250

    img.y = 150

end

if media.hasSource(media.Camera) then

        media.capturePhoto( {listener = onComplete, destination = {baseDir=system.TemporaryDirectory, filename=“image.jpg”,        type=“image”} } )

end

Best Regards,

Team, SP Technolab

www.sptechnolab.com

Hi SP Technolab

Thanks for your advice.

I tried your code,

But listener event was not called…

I use Nexus 7.

What device do you use for check?

I tested in Goggle Nexus.

I am using corona Build: 2014.2189

Best Regards,

Team, SP Technolab

www.sptechnolab.com

Hi @Naofumi,

Is your “sessionComplete” function in the proper scope? Can you post how that function looks?

Thanks,

Brent

Hi Brent,

Thank you for your replay.

“sessionComplete” function is as below.

local sessionComplete = function(event) print('go to editing scenes') composer.gotoScene('scenes.edit') end

Scene was not change.

I checked logs, but “go to editing scenes” was not output…

By the way, I’m Enterprise licensed user, 

but my license is displayed “Pro”.

Why…?

Thanks, and is that function in the proper Lua scope?

Yes, Hrea is the code.

local sessionComplete = function(event) print('go to editing scenes') composer.gotoScene('scenes.edit') end if media.hasSource( media.Camera ) then media.capturePhoto( { listener = sessionComplete , destination = { baseDir=system.TemporaryDirectory, filename="sc.jpg", type="image" } } ) else native.showAlert("Corona", "Camera not found.") end

I can get event when took a picture on simulator.

What I’m seeing is that media.capturePhoto will fail to return correctly if the file you are trying to save to does not already exist. It seems like it’s trying to delete the old file, before saving the new one, but if the file does’t exist you get an error.

I also see this in the simulator. Try removing the file sc.jpg and run the code in the simulator and see if it gives you an error message on the first run.

I tried to remove “sc.jpg”, but “onComplete” was not called.

 if system.getInfo('platformName') ~= 'iPhone OS' and event.target.id=='camera' then local sessionComplete = function(event) local image = event.target if image then display.save( image,'sc.jpg',system.TemporaryDirectory) composer.gotoScene('scenes.edit') display.remove(image) end end if media.hasSource( media.Camera ) then os.remove( system.pathForFile( "sc.jpg" ,system.TemporaryDirectory) ) media.capturePhoto( { listener = sessionComplete , destination = {baseDir=system.TemporaryDirectory, filename="sc.jpg", type="image"} } ) else native.showAlert("Corona", "Camera not found.") end else composer.gotoScene('scenes.'..event.target.id,{effect='fade',time=200}) end

Hi Naofumi Ozawa

Try this code.

This code work fine for me.

local function onComplete(event)

   local photo = event.target

   print( “onComplete called …” )

    local img = display.newImageRect(“image.jpg”,system.TemporaryDirectory,200,200)

    img.x = 250

    img.y = 150

end

if media.hasSource(media.Camera) then

        media.capturePhoto( {listener = onComplete, destination = {baseDir=system.TemporaryDirectory, filename=“image.jpg”,        type=“image”} } )

end

Best Regards,

Team, SP Technolab

www.sptechnolab.com

Hi SP Technolab

Thanks for your advice.

I tried your code,

But listener event was not called…

I use Nexus 7.

What device do you use for check?

I tested in Goggle Nexus.

I am using corona Build: 2014.2189

Best Regards,

Team, SP Technolab

www.sptechnolab.com