Media.show() Does Not Send Target

I am using media.show(media.[Camera, PhotoLibrary], sessionComplete, fileSaveTable) with the latest stable build and am getting some odd results on my Android device. First, I am not able to save the image to any directory and two, the event table passed to sessionComplete only has “name” and “completed” fields.

The stripped down code is :
[lua] local fileSaveTable = {baseDir = system.TemporaryDirectory, filename = “le.png”}–or Documents
media.show(media.PhotoLibrary, sessionComplete, fileSaveTable)–or Camera[/lua]

Here is the sessionComplete function:
[lua]local sessionComplete = function( event )
local target = event.target
printr( event )
if not target then
local file = io.open(system.pathForFile(“le.png”, system.TemporaryDirectory), “r”)
if file then
print(“Found File”)
else
print(“File does not Exist!!!”)
end
end[/lua]

I get “File does not Exist!!!” from adb. And then, printr returns “name”=“completion” and “completed” = true", but I do not get any userdata for target or even a nil target entry.
[import]uid: 169884 topic_id: 34118 reply_id: 334118[/import]

Hmm. This sounds suspiciously familiar to my own current problem with media.show (thread link). [import]uid: 41884 topic_id: 34118 reply_id: 135664[/import]

Are you testing on Android or iOS?
[import]uid: 169884 topic_id: 34118 reply_id: 135666[/import]

I’m testing on iOS (problem noticed in Mac OSX simulator though) [import]uid: 41884 topic_id: 34118 reply_id: 135667[/import]

Well, it is good to know that it is not just an Android problem. Now, try it on your device. I updated an iOS app and didn’t notice the problem until I started updating my Android build…iOS devices should be okay. [import]uid: 169884 topic_id: 34118 reply_id: 135674[/import]

This has come up a couple of times. Let me see if I can get someone to look at this.

Rob
[import]uid: 199310 topic_id: 34118 reply_id: 135703[/import]

If you tell [lua]media.show()[/lua] to save to file, then [lua]event.target[/lua] will be nil and will not automatically load the selected image as a display object. This is because some developers do not want this API to automatically display the selected photo and they want to, say, upload it to a server instead.

In order to know if a photo was selected at all, then you need to check if [lua]event.completed[/lua] was set [lua]true[/lua]. If it is [lua]true[/lua], then this indicates that the API has finished saving the photo to file and and is now accessible.

I’ve also noticed that your code is missing an [lua]end[/lua] statement. It should look like this…
[lua]local sessionComplete = function( event )
if event.completed then
local file = io.open(system.pathForFile(“le.png”, system.TemporaryDirectory), “r”)
if file then
print(“Found File”)
else
print(“File does not Exist!!!”)
end
end – end

local fileSaveTable = {baseDir = system.TemporaryDirectory, filename = “le.png”}
media.show(media.PhotoLibrary, sessionComplete, fileSaveTable)[/lua]
[import]uid: 32256 topic_id: 34118 reply_id: 135708[/import]

Thanks Joshua, now let’s say that if my implemented code is better than my demo code :), why would I still get the “File does not Exist” print out? [import]uid: 169884 topic_id: 34118 reply_id: 135750[/import]

I’ll take a look at this to help troubleshoot my issue, but then I guess the docs need to explain what onComplete means for media.show() devices. ie: does media.Camera’s onComplete mean upon snapping the photo or saving the photo?

Checking event.completed is great for a variety of reasons but if you only get one onComplete call and it happens before the image is saved, I’m not sure how to handle that… [import]uid: 41884 topic_id: 34118 reply_id: 135751[/import]

Richard,

The onComplete() function does not get called until *after* the photo has been saved to file. I’ve tested this for myself on Android by having [lua]media.show(“camera”, …)[/lua] save to file and then called [lua]display.newImage()[/lua] on that photo file to display it. It was working fine for me.

Also, please note that the Corona Simulator does not support saving images to file via the [lua]media.show()[/lua] function. This functionality is currently only supported on iOS and Android. We plan on adding this functionality to the Corona Simulator in the future. [import]uid: 32256 topic_id: 34118 reply_id: 135947[/import]

Omega,

I thought your [lua]local file[/lua] variable was falling out of scope due to the missing [lua]end[/lua] statement and then your [lua]if file then[/lua] check was then looking up a global “file” variable that didn’t exist and would return [lua]nil[/lua]. That’s what I was thinking. :slight_smile:

Let me ask you this. Are you seeing this problem on iOS or Android?
I’ve tested this out on Android and it worked for me.

Also note that our [lua]media.show()[/lua] API cannot save to file in the Corona Simulator and will display an image instead. This is because we haven’t added this functionality to the simulator yet. [import]uid: 32256 topic_id: 34118 reply_id: 135948[/import]

Thanks Joshua. I solved the issue. I was looking for a png and not a jpg :slight_smile: [import]uid: 169884 topic_id: 34118 reply_id: 135952[/import]

Hmm. This sounds suspiciously familiar to my own current problem with media.show (thread link). [import]uid: 41884 topic_id: 34118 reply_id: 135664[/import]

Are you testing on Android or iOS?
[import]uid: 169884 topic_id: 34118 reply_id: 135666[/import]

I’m testing on iOS (problem noticed in Mac OSX simulator though) [import]uid: 41884 topic_id: 34118 reply_id: 135667[/import]

Well, it is good to know that it is not just an Android problem. Now, try it on your device. I updated an iOS app and didn’t notice the problem until I started updating my Android build…iOS devices should be okay. [import]uid: 169884 topic_id: 34118 reply_id: 135674[/import]

This has come up a couple of times. Let me see if I can get someone to look at this.

Rob
[import]uid: 199310 topic_id: 34118 reply_id: 135703[/import]

If you tell [lua]media.show()[/lua] to save to file, then [lua]event.target[/lua] will be nil and will not automatically load the selected image as a display object. This is because some developers do not want this API to automatically display the selected photo and they want to, say, upload it to a server instead.

In order to know if a photo was selected at all, then you need to check if [lua]event.completed[/lua] was set [lua]true[/lua]. If it is [lua]true[/lua], then this indicates that the API has finished saving the photo to file and and is now accessible.

I’ve also noticed that your code is missing an [lua]end[/lua] statement. It should look like this…
[lua]local sessionComplete = function( event )
if event.completed then
local file = io.open(system.pathForFile(“le.png”, system.TemporaryDirectory), “r”)
if file then
print(“Found File”)
else
print(“File does not Exist!!!”)
end
end – end

local fileSaveTable = {baseDir = system.TemporaryDirectory, filename = “le.png”}
media.show(media.PhotoLibrary, sessionComplete, fileSaveTable)[/lua]
[import]uid: 32256 topic_id: 34118 reply_id: 135708[/import]

Thanks Joshua, now let’s say that if my implemented code is better than my demo code :), why would I still get the “File does not Exist” print out? [import]uid: 169884 topic_id: 34118 reply_id: 135750[/import]

I’ll take a look at this to help troubleshoot my issue, but then I guess the docs need to explain what onComplete means for media.show() devices. ie: does media.Camera’s onComplete mean upon snapping the photo or saving the photo?

Checking event.completed is great for a variety of reasons but if you only get one onComplete call and it happens before the image is saved, I’m not sure how to handle that… [import]uid: 41884 topic_id: 34118 reply_id: 135751[/import]