0

I have a flash as3 based webcam video recorder that publishes the webcam video stream and to do this i am using the following codes :

var camera:Camera = Camera.getCamera(0);
var arr:Array = Camera.names;
if(camera != null)
{
    videoWidth = topBorderContainer.width;
    videoHeight = topBorderContainer.height;
    camera.setMode(videoWidth, videoHeight, 30, false);
    camera.setQuality(0, 100);
    if (camera)
    {
        videoDisplay.videoObject.attachCamera(camera);
    }
}

But problem is that if i am connecting a new document camera at run time and running my webcam tool then Camera.names returning the previously connected document camera name instead of returning the new document camera name.

And to get new document webcam name i have to restart my application again.

But i have no knowledge how to get newly connected document camera name at run time so if anybody know how to get the newly connected document camera name at run time please help me to solve.

Babu
  • 440
  • 5
  • 23
  • _"if i am connecting a new document camera at run time and running my webcam tool then Camera.names returning the previously connected document camera name instead of returning the new document camera name."_ What are you doing to detect the new camera (to update camera names list)? You need to put `Camera.getCamera(0);` in a function that you can run whenever you need to like so `checkCamera();`... where `function checkCamera() : void` has the logic for getting names etc. – VC.One Jan 30 '17 at 16:43
  • Hi @VC.One ,actually my problem is that if i am disconnection the previously connected document camera and connecting a new document camera at run-time and if i am running my webcam tool then also i am getting the previously connected document camera name instead of getting the currently connected document camera name due to which i am not getting any video images in my webcam tool as the previous one already disconnected. So my question is that how to update the camera name as current because `Camera.getCamera(0)` still returning previous one (I am only connectiong one camera) – Babu Jan 31 '17 at 06:54

1 Answers1

1

It is very likely that you will not be able to pull the trick:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()

"Scanning the hardware for cameras takes time. When the runtime finds at least one camera, the hardware is not scanned again for the lifetime of the player instance. However, if the runtime doesn't find any cameras, it will scan each time getCamera is called. This is helpful if the camera is present but is disabled; if your SWF file provides a Try Again button that calls getCamera, Flash Player can find the camera without the user having to restart the SWF file."

It is possible that Flash Player treats Workers (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html) as separate Flash Player instances and thus a new Worker would be able to access the renewed list of Cameras. You might want to try it.

Organis
  • 7,243
  • 2
  • 12
  • 14
  • _"...If your SWF app provides a `"Try Again"` button that calls a function with `getCamera`, Flash Player can try to find the camera without the user having to restart the SWF file."_ isn't that the solution? – VC.One Jan 30 '17 at 16:40
  • @VC.One not really. It is about the case the camera wasn't present (disabled or detached) during the first getCamera(...) call. Once FP have found any valid Camera object (which is a predicament to OP question), it will not scan for cameras again. Or so they say. – Organis Jan 30 '17 at 16:52
  • Hi @Organis ,actually my problem is that if i am disconnection the previously connected document camera and connecting a new document camera at run-time and if i am running my webcam tool then also i am getting the previously connected document camera name instead of getting the currently connected document camera name due to which i am not getting any video images in my webcam tool as the previous one already disconnected. So do you have any knowledge how to refresh document camera so that i will get currently connected camera name (I am connecting one webcam at a time). – Babu Feb 01 '17 at 06:50
  • @Ashish please re-read the paragraph I quoted from official documentation. Once Flash Player finds a valid Camera, it **does not** re-scan hardware to refresh the list. – Organis Feb 01 '17 at 07:15
  • @Ashish, the idea with Workers is a wild guess and will probably not work. I don't think you **can** solve it with the pure AS3, but you probably can by inconveniencing the user with reload of the web page, or re-creating Flash HTML Object tags, or restarting AIR application (if you publish AIR): http://stackoverflow.com/questions/1821749/how-to-restart-a-standalone-adobe-air-flex-application – Organis Feb 01 '17 at 08:16