简体   繁体   中英

Flex mobile Camera + Native extension

I've already asked this question on Adobe prerelease forum, but they keep silence, so I need your help!

I need to make an application that should be able to turn ON/OFF flash light on Android device during live video streaming to server.

So I made and extension. Java function is simple:

 try{ 
   if (isOn){
     camera = Camera.open();
       Parameters params = camera.getParameters();
       params.setFlashMode(Parameters.FLASH_MODE_TORCH);
       camera.setParameters(params);
     } else {
        camera.release();
     }     
     } catch( Exception e ){
 }

I used HTC desire S with front and rear camera. When I do streaming from air application (using as3 camera = Camera.getCamera()) and try to use this extension, it doesn't respond at all

So I found workaround: in flash I've changed code to:

 camera = null;
 nativeExtension.turnFlashOn(true);
 camera = Camera.getCamera("1");

This code works only when I use rear camera, but i need to pass argument "1" which is actually front camera, but rear camera is used in this case. Anyway - it works fine.

But when I tried to use this application on HTC with only rear camera, I stucked... I cannot use Camera.getCamera("1") because I have only "0" camera, which is rear camera. So when I use this code:

 camera = null;
 nativeExtension.turnFlashOn(true);
 camera = Camera.getCamera("0");

my image freezes for both sides (Android app and on the other side) and it goes normal when the flash is off

I think this is because you still have the camera open in the native extension. You are only releasing it when you run nativeExtension.turnFlashOn(false)

The camera resource can only be held by one process at a time. This is why it is freezing. I suspec if you look at your system logs (logcat) you will see errors like "Unable to connect to camera" When your flash is off, you have run camera.release() so it isn't being held and AS can acquire it.

I am not sure whats going down in AS where your requesting the front camera but using back. You aren't very clear. Either way, dont do this because your desired result can not be done, because it would require two processes holding the camera resource at the same time.

Why dont you do your streaming from your native extension? That way you can use the camera and flash at the same time, and performance may be alot better since it is running natively. Flex's support for the Camera and recording video is really poor. I was going to use it and eventually decided to move all my camera processes to a NE.

Hope this helps

If your device has 0, 1, 2 cameras installed try this logic

 camera = null;
 nativeExtension.turnFlashOn(true);
// get front camera
camera = Camera.getCamera("1");
// if no front cam try back
if (camera == null)
 camera = Camera.getCamera("0");
// if no cams try default cam
if (camera == null)
 camera = Camera.getCamera();
else {
  trace("Mobile device has no camera!");
}

This code works on device with zero, 0, or 2 cams

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM