Access device camera from a webpage

9 posts / 0 new
Last post
ChrilleZ_74
ChrilleZ_74's picture
Offline
Joined: 6 Dec 2011
Posts:
Access device camera from a webpage

Hi!

I've been testing the CameraDemo example and the standard WebView/Wormhole example for communication between Javascript and C++.
What I wanna do is from a webpage access the device camera, take a picture and return it to the webpage.
Anyone know if this is possible??

Thanks!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, I should think that it is possible, but you won't be able to pipe the camera viewscreen to the webpage any more than you can show your webcam on your desktop. You need to write a wormhole function which takes the picture, saves it to somewhere (probably an online resource) and returns the URL to the webpage. I would probably create a new screen with a CameraPreview widget. This screen will take care of the picture taking and uploading, and pass the URL to the WebView screen. The WebView screen can then pass it on to the HTML.

Let me know if you need help in doing this.

ChrilleZ_74
ChrilleZ_74's picture
Offline
Joined: 6 Dec 2011
Posts:

Ok, sounds like an ok solution.
I've created a new project, javascript/C++, in mosync IDE and copied the files from the CameraDemo example into this project.
Then when I get the message "Camera" from the webpage I try to create and show the AppScreen from the CameraDemo.
But in the show function the call to maCameraStart() returns -2 witch is an errorcode, but I can't find anywhere what it means.
I am using a Samsung 10.1 to test this on.
I've attached the main.cpp file of my project if you wan't to take a look at it.

AttachmentSize
main_cpp.zip 3.7 KB
Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

-2 means

I should try a few things. maCameraFormatNumber() will return the number of image sizes you can get. A negative number means that there isn't a camera available, so you can use this to test easily. maCameraStart() will start a full-screen view finder. You can start it in a widget with:

maCameraSetPreview(myCameraWidget->getWidgetHandle());

assuming you're using NativeUI. I'll see if I can look at your code in a few minutes.

ChrilleZ_74
ChrilleZ_74's picture
Offline
Joined: 6 Dec 2011
Posts:

I did a simple test project.
Here is my wormhole function.

void handleWebViewMessage(WebView* webView, MAHandle urlData)
    {
        WebViewMessage message(webView, urlData);

        if (message.is("CheckCamera"))
        {
            String res = Convert::toString(maCameraNumber());

            char buffer[200];
            sprintf(buffer, "Result('%s')", res.c_str());
            callJS(buffer);

        }

        callJS("bridge.messagehandler.processedMessage()");
    }

When I run this I get -2 in res.

Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Cool - Convert::toString() :-) I love it, and use it all the time, but you don't need it here.

int res = maCameraNumber();
char buffer[200];
sprintf(buffer, "Result('%d')", res);
callJS(buffer);

However, -2 does mean that MA_CAMERA_RES_FAILED in maappi.h.  Hang on, I'm asking around, because I think that should work.  Are you using MoSync 2.7?

 

Sam Pickard
rival's picture
Online
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, the news is that we've definitely got people here who've seen the camera working on a Galaxy 10.1. We don't officially support Honeycomb yet, but I'm told that CameraDemo app in the examples folder should work. Can you load that app and try it on your 10.1?

ChrilleZ_74
ChrilleZ_74's picture
Offline
Joined: 6 Dec 2011
Posts:

Yes, I'm using MoSync 2.7 and the CameraDemo app works fine on my 10.1

bild2.JPG
ChrilleZ_74
ChrilleZ_74's picture
Offline
Joined: 6 Dec 2011
Posts:

Wow, that thumbnail is quite big :-)