views:

328

answers:

2

I'm having trouble with Camera.getCamera() in Flash AS3. If there are multiple camera drivers, it does not necessarily pick the correct one. If the default is the correct, the program works fine; however, if another driver is selected as the default then LED on the webcam does not come on and no video is captured. I can cycle through the available cams and select an arbitrary one. I don't, however, know how to determine if the selected camera is correct. It is not returning null. I considered using camera.currentFPS, but it's not clear when this gets updated. I'm really struggling to determine dynamically which camera will do the trick!

+1  A: 

Check out this blog post, it could be of use for what you're trying to do.

I remeber I used this class a while ago, because there were problems detecting the right webcam in Macs in an app I was working on. Never experienced this problem for Windows or Linux, though.

I was on a rather tight deadline then, so I didn't really investigate much about the subject. I remember this code had some problems with some built-in cameras in laptops running Windows. I ended up just checking flash.system.Capabilities.os to detect whether the client was a Mac or not. For Macs, I used the code in this class, as is. For everything else, I just detected the camera the "regular way" (i.e., getting the default camera). It worked fine in all our tests, and since time was short, that settled it.

To be honest, though, I'm not sure if it covers some corner cases. You might want to check that, but hopefully, this will give you at least some pointers -- if not a solution.

Hope this helps.

Juan Pablo Califano
This is so so close to being the right solution-- that is, api to this class is just what I'm looking for, but I'm not quite getting it to work. My understanding is that after instantiating a CameraDetection and calling begin() on it, I should shortly dispatch a CameraEvent, which will call my onResolve() method. This never happens.
Ben
I ended up having to add a few extra lines to get the class working, but it seems to be doing the trick now. The problem was that no camera status events would be dispatched, so I worked around this by using setInterval to check if the camera was muted repeatedly. Once a selection was made, it worked fine. private var waitCheckInterval:uint; private function waitCheck():void{ trace('Camera is muted? ' + _camera.muted); if (_camera.muted){ return; } clearInterval(waitCheckInterval); checkCamera(); }
Ben
A: 

The thing you want is probably activityLevel http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/media/Camera.html#activityLevel But if you're just having issues selecting the "correct" camera in OSX I suggest you use a drop down and let the user select. Use the Camera.names to fill the selection drop-down and use the selected index to do the actual selection. One major gotcha is to make sure you use a string to select the camera, it is the opposite of Microphone selection wherein a number is used.

//camera uses string
var camera:Camera = Camera.getCamera("0");

//microphone uses number
var mic:Microphone = Microphone.getMicrophone(0);

//method to handle the selection of a new camera
private function changeCamera(evt:ListEvent):void {
    camera = Camera.getCamera(evt.currentTarget.selectedIndex.toString());
}

I have seen differences with windows and osx myself but I don't recall the exact problem.

Mondain
It's a good thought, but this does not work for several reasons. First, the requirement is to have this take place automatically. A more standard way of user selection of the camera is Security.showSecurityPanel(SecurityPanel.CAMERA), but again, I am not trying to ask the user to select-- in most cases there is one and only one correct camera, and the user will not know by looking at a list of names which it is.
Ben